saveMovie {animation} | R Documentation |
This function opens a graphical device first to generate a sequence of images, then makes use of the command convert in `ImageMagick' to convert these images to a single animated movie (in formats such as GIF and MPG, etc).
saveMovie(expr, interval = 1, moviename = "movie", movietype = "gif", loop = 0, dev = png, filename = "Rplot", fmt = "%03d", outdir = tempdir(), ...)
expr |
an expression to generate animations; use either the animation functions (e.g. brownian.motion(nmax = 30) ) in this package or a custom expression (e.g. for(i in 1:10) plot(runif(10), ylim = 0:1) ). |
interval |
duration between animation frames (unit in seconds) |
moviename |
file name of the movie (base only, without extension) |
movietype |
format of the movie ('gif', 'mpg', ...; as long as it's supported by ImageMagick) |
loop |
iterations of the movie; set iterations to zero to repeat the animation an infinite number of times, otherwise the animation repeats itself up to loop times (N.B. for GIF only!) |
dev |
a function for a graphical device such as png , jpeg and bmp , etc. |
filename |
file name of the sequence of images (`pure' name; without any format or extension) |
fmt |
a C-style string formatting command, such as %3d |
outdir |
the directory for the movie frames and the movie itself |
... |
other arguments passed to the graphical device, such as height and width , ... |
The convenience of this function is that it can create a single movie file, however, two drawbacks are obvious too: (1) we need a special (free) software ImageMagick; (2) the speed of the animation cannot be conveniently controlled, as we have specified a fixed interval
. So just go ahead with this function to create your movies if you don't mind these two points.
An integer indicating failure (-1) or success (0) of the converting (refer to system
).
Creating HTML animation pages will not require any other software to be installed, and the duration of animations can also be controlled; refer to ani.start
and ani.stop
.
Yihui Xie
http://www.imagemagick.org/script/convert.php
system
, ani.start
, ani.stop
, png
## make sure ImageMagick has been installed in your system ## Not run: saveMovie(for(i in 1:10) plot(runif(10), ylim = 0:1), loop = 1) saveMovie(brownian.motion(nmax = 40), width = 600, height = 600) ## End(Not run)