2

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?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Michael Lee
  • 323
  • 2
  • 11
  • R on Windows sometimes doesn't do anti-aliasing well, see: http://stackoverflow.com/questions/6023179/anti-aliasing-in-r-graphics-under-windows-as-per-mac which may help. – Marius May 05 '17 at 03:03
  • Thanks for the reply - I tried setting `animation::ani.options(antialias = "cleartype")` as suggested in the docs but doesn't appear to have any effect on the ouput; I also don't think this would explain the pixelated geoms. – Michael Lee May 05 '17 at 14:52
  • You may have changed the text rendering settings- but AFAIK antialiasing *does* affect geoms and to fix it you need to use a different output device like Cairo- I think there's an ani.dev option – Marius May 05 '17 at 22:31
  • `ani.options()` does not seem to be provided by any of those packages today. Was the `animation` package previously a dependency of one of those? – randy Oct 13 '22 at 20:40
  • @randy as the time of writing this question the [readme for `gganimate`](https://github.com/thomasp85/gganimate/tree/2cb5ced0235b181d9ec2fdd2d8f31d4d8d985cbc#readme) referenced `ani.options()` could be "passed directly to gganimate or to ani.options beforehand" to customize the output – Michael Lee Oct 20 '22 at 14:12

1 Answers1

0

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)