Jan Verbesselt
2005-Jul-27 10:11 UTC
[R] HOW to Create Movies with R with repeated plot()?
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)? Regards, Jan _________________________________________________________________ Ir. Jan Verbesselt Research Associate Group of Geomatics Engineering Department Biosystems ~ M³-BIORES Vital Decosterstraat 102, 3000 Leuven, Belgium Tel: +32-16-329750 Fax: +32-16-329760 http://gloveg.kuleuven.ac.be/ _______________________________________________________________________ [[alternative HTML version deleted]]
Martyn Plummer
2005-Jul-27 13:23 UTC
[R] HOW to Create Movies with R with repeated plot()?
On Wed, 2005-07-27 at 12:11 +0200, Jan Verbesselt wrote:> 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)?You can use ImageMagick tools to convert a set of bitmap files into an animated GIF. For example, in R, this creates 101 separate png files: x <- seq(-1,1,length=101) y <- x^2 png() for (i in 1:length(y)) { plot(x[1:i], y[1:i], xlim=c(-1,1), ylim=c(0,1), type="l") } dev.off() Then, on the command line (on Linux) this joins them together convert -delay 10 Rplot*.png Rplot.gif animate Rplot.gif You can also create MNG format, but this is less widely supported. Martyn ----------------------------------------------------------------------- This message and its attachments are strictly confidential. ...{{dropped}}
François Pinard
2005-Jul-27 14:25 UTC
[R] HOW to Create Movies with R with repeated plot()?
[Jan Verbesselt]> 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)?You may also peek at an actual example of using R for mini-movies: http://pinard.progiciels-bpi.ca/plaisirs/animations/index.html I wrote this toy about the same week I started to learn R, and it was a hell of a good exercise for the poor little me! :-) -- Fran??ois Pinard http://pinard.progiciels-bpi.ca
"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
On 27-Jul-05 Jan Verbesselt wrote:> 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)?A similar question was discussed on R-help some months ago: Start at Cari G Kaufman <cgk at stat.cmu.edu>, "[R] animation without intermediate files?" Thu, 6 Jan 2005 16:21:36 -0500 (EST) However, this is not quite your question! It seems you would be content with making a movie out of files already saved from R, so it's not a "real-time" situation. There are several approaches you could adopt. One (if you are using Linux with ImageMagick installed -- or if this is available for your platform if different) is to use the program 'animate' in that suite of programs. The format of the image files does not matter for 'animate' (though I think all should have the same format), so they could be .jpg, .gif, etc. Suppose you had a set of files graph001.jpg graph001.jpg ... graph100.jpg then the command animate graph*.jpg would present them as an animation in due order. There are several options to the 'animate' command which you can use to control features of how they are displayed. One you would probably want to use is "-delay" -- e.g. animate -delay 7 graph*.jpg would pause for 7/100 seconds between successive images. Another option is to create an "animated GIF" -- a single file which encapsulates several images and displays them in sequence when the file is opened with suitable software (most Web browsers do this well; likewise so does ImageMagick's 'display'). Programs which can create animated GIFs include the GIMP and gifsicle in the Free Software world. There are also several programs for non-Linux platforms. Sorry I can't help with suggestions for creating .avi files. Best wishes, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 27-Jul-05 Time: 14:08:00 ------------------------------ XFMail ------------------------------
Vehbi Sinan Tunalioglu
2005-Jul-27 18:45 UTC
[R] HOW to Create Movies with R with repeated plot()?
Hi, Here was a short tutorial about howto do that: http://r.vsthost.com/wordpress/2005/07/01/creating-video-files-on-gnulinux-using-r/ PS: You can submit such short articles or tutorials, if you have time. I was thinking to add more stuff, but these days I don't have much time. --Vehbi Sinan Jan Verbesselt wrote:> 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)? > > > > Regards, > > Jan > > _________________________________________________________________ > Ir. Jan Verbesselt > Research Associate > Group of Geomatics Engineering > Department Biosystems ~ M??-BIORES > Vital Decosterstraat 102, 3000 Leuven, Belgium > Tel: +32-16-329750 Fax: +32-16-329760 > http://gloveg.kuleuven.ac.be/ > _______________________________________________________________________ > > > > > [[alternative HTML version deleted]] > > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Possibly Parallel Threads
- Penalized likelihood-ratio chi-squared statistic: L.R. model for Goodness of fit?
- How to add values on the axes of the 3D bi-variable lrm fit?
- How to add legend of plot.Design function (method=image)? (if (!.R.) )
- Change labels of x-axes in Plot of stl() function?
- Spatial Autocorrelation for point data