简体   繁体   中英

Gif/Mp4 quality using R animation/gganimate package different across Linux/Windows operating systems

Using the same code script, R/Imagemagick produces outputs of different image quality depending on the operating system that runs the script. Notably, the geoms and text in the windows version are noticeably more pixelated.

Here are links to the Linux (ubuntu 16.04) and Windows (I believe 7 Professional) gifs created via the following code script, via the README of Thomas Pederson's tweenr package :

library(ggplot2)
library(gganimate)
library(ggforce)
library(tweenr)

# this line is included to link to imagemagick in Windows, not needed in Linux
ani.options(convert = 'C:/Program Files/ImageMagick-7.0.4-Q16/magick.exe')

# Making up data
t <- data.frame(x=0, y=0, colour = 'forestgreen', size=1, alpha = 1, 
                stringsAsFactors = FALSE)
t <- t[rep(1, 12),]
t$alpha[2:12] <- 0
t2 <- t
t2$y <- 1
t2$colour <- 'firebrick'
t3 <- t2
t3$x <- 1
t3$colour <- 'steelblue'
t4 <- t3
t4$y <- 0
t4$colour <- 'goldenrod'
t5 <- t4
c <- ggforce::radial_trans(c(1,1), c(1, 12))$transform(rep(1, 12), 1:12)
t5$x <- (c$x + 1) / 2
t5$y <- (c$y + 1) / 2
t5$alpha <- 1
t5$size <- 0.5
t6 <- t5
t6 <- rbind(t5[12,], t5[1:11, ])
t6$colour <- 'firebrick'
t7 <- rbind(t6[12,], t6[1:11, ])
t7$colour <- 'steelblue'
t8 <- t7
t8$x <- 0.5
t8$y <- 0.5
t8$size <- 2
t9 <- t
ts <- list(t, t2, t3, t4, t5, t6, t7, t8, t9)

tweenlogo <- data.frame(x=0.5, y=0.5, label = 'tweenr', stringsAsFactors = F)
tweenlogo <- tweenlogo[rep(1, 60),]
tweenlogo$.frame <- 316:375

# Using tweenr
tf <- tween_states(ts, tweenlength = 2, statelength = 1, 
                   ease = c('cubic-in-out', 'elastic-out', 'bounce-out', 
                            'cubic-out', 'sine-in-out', 'sine-in-out', 
                            'circular-in', 'back-out'), 
                   nframes = 375)

# Animate with gganimate
p <- ggplot(data=tf, aes(x=x, y=y)) + 
  geom_text(aes(label = label, frame = .frame), data=tweenlogo, size = 13) + 
  geom_point(aes(frame = .frame, size=size, alpha = alpha, colour = colour)) + 
  scale_colour_identity() + 
  scale_alpha(range = c(0, 1), guide = 'none') +
  scale_size(range = c(4, 60), guide = 'none') + 
  expand_limits(x=c(-0.36, 1.36), y=c(-0.36, 1.36)) + 
  theme_bw()
animation::ani.options(interval = 1/15)
gganimate(p, "dancing ball.gif", title_frame = F, ani.width = 800, 
           ani.height = 800)

Finally, here are the animation options in running on Ubuntu:

> animation::ani.options()
$interval
[1] 0.06666667

$nmax
[1] 50

$ani.width
[1] 480

$ani.height
[1] 480

$imgdir
[1] "images"

$ani.type
[1] "png"

$ani.dev
[1] "png"

$title
[1] "Animations Using the R Language"

$description
[1] "Animations generated in R version 3.4.0 (2017-04-21) using the package animation"

$verbose
[1] TRUE

$loop
[1] TRUE

$autobrowse
[1] TRUE

$autoplay
[1] TRUE

$use.dev
[1] TRUE

$ffmpeg
[1] "ffmpeg"

Since there are quite a bit of dependencies that go into creating the visualization, I'm a bit stumped on where to address changes. What revisions need to be made to improve the quality of the Windows version? I've heard that convert in Imagemagick is deprecated, perhaps something relating to that connection?

Try playing around with res values. A resolution of 300 might alter the size of everything so just keep an eye on it.

gganimate(p, "dancing ball.gif", title_frame = F, ani.width = 800, 
           ani.height = 800,res=300)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM