loopings GIFs with animation package in R

2019-04-16 01:20发布

问题:

I'm trying to create a GIF that loops with the animation package in R. But for some reason, even if I set the option loop=TRUE, the images I make only play once and then stop. I would like the GIF to keep playing indefinitely. Any tips?

install.packages("animation")
library(animation)

saveGIF({
  for (i in 1:10) plot(runif(10), ylim = 0:1)
},loop=TRUE,interval=0.2)

回答1:

The following works for me. loop=TRUE is the default setting. Are you sure that the problem is not in your GIF viewer?

library(animation)

ani.options(
convert = shQuote('C:/Program Files (x86)/ImageMagick-6.8.1-Q16/convert.exe')
)

saveGIF(
{
  for (i in 1:10) plot(runif(10), ylim = 0:1)
},
movie.name = "test.gif", 
interval = 0.2, 
ani.width = 300, 
ani.height = 300,
outdir = getwd()
)

p.s. I'm guessing that your code works without the addition of the pointer to the convert.exe program since you are able to produce the .gif.