Is there an easy way to create a "movie" by stitching together several plots, within R?
If you need to save the animation for later use you can use the anim_save() function. It works much like ggsave() from ggplot2 and automatically grabs the last rendered animation if you do not specify one directly.
Here is one method I found using R help:
To create the individual image frames:
jpeg("/tmp/foo%02d.jpg") for (i in 1:5) { my.plot(i) } dev.off()
To make the movie, first install ImageMagick. Then call the following function (which calls "convert", part of ImageMagick I suppose):
make.mov <- function(){ unlink("plot.mpg") system("convert -delay 0.5 plot*.jpg plot.mpg") }
Or try using the ffmpeg function as described in this article (I've found this gives cleaner results): ffmpeg -r 25 -qscale 2 -i tmp/foo%02d.jpg output.mp4
May require a bit of tinkering, but this seemed pretty simple once everything was installed.
Of course, anywhere you see "jpg" or "jpeg", you can substitute GIF or PNG to suit your fancy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With