[R] HOW to Create Movies with R with repeated plot()?
Earl F. Glynn
efg at stowers-institute.org
Wed Jul 27 16:39:37 CEST 2005
"Jan Verbesselt" <Jan.Verbesselt at biw.kuleuven.be> wrote in message
news:000e01c59293$80ee5d00$1145210a at agr.ad10.intern.kuleuven.ac.be...
Dear R-helpers,
Is it possible to create a type of 'movie' in R based on the output of
several figures (e.g., jpegs) via the plot() function. I obtained dynamic
results with the plotting function and would like to save these as a movie
(e.g., avi or other formats)?
1) You can create animated GIFs with the caTools package.
2) ImageMagick (clipped from R-Help)
It is quite easy to do with ImageMagick (www.imagemagick.org), which can be
installed on most OSes. I tried this simple sequence and it worked
beautifully.
In R:
> for(i in 1:5) {
+ jpeg(paste("fig", i, ".jpg", sep = ""))
+ hist(rnorm(100))
+ dev.off()
+ }
Then from the command line (I tried it using Linux, though it should be the
same on any platform):
% convert -delay 50 -loop 50 fig*.jpg animated.gif
This created animated.gif, a nice animation of my sequence of files. You
can control the timing of the animation by playing with -delay and -loop.
3) TCL/TK Animation (clipped from R-Help)
The tcltk package also has ways of doing this kind of stuff:
library(tcltk)
f <- function(){plot(rnorm(1000)); tkcmd("after", 1000,f)}
f()
(To stop, set f <- NULL)
efg
More information about the R-help
mailing list