htbPlotAnim | R Documentation |
Creates a movie clip from sequential graphical outputs.
htbPlotAnim(
filename,
width,
height,
expr,
type = c("mp4", "gif"),
img = c("png", "jpg"),
converter = NULL,
digit = 5,
kbps = "300k",
fps = 10,
recursive = TRUE,
scale = 100,
transparent = "",
verbose = TRUE
)
filename |
A string. The name of the created movie file.
The extension (.eps) can be omitted
if valid file type is designamted by |
width |
A numeric. The width of the device in pixels. |
height |
A numeric. The height of the device in pixels. |
expr |
An expression. R codes to plot a set of static images that are then converted in a movie file. Use braces (curly bracket) to enclose multiple lines of code without bothersome semicolons between commands. |
type |
A string. The type of the animated output.
Either |
img |
A string. The name of the output device for plotting.
Either |
converter |
A string. The name of the command to compile
static images into a movie.
Either |
digit |
An integer. The number of digits reserved for
plotting static frames.
Default value |
kbps |
An integer. An approximate target bit rate
for mp4 output passed to |
fps |
An integer. The frame rate of the movie. |
recursive |
A logical. Whether to make the animated gif file
to be recursively looped or not.
Ignored when using |
scale |
A numeric. Rescaling parameter used during
creation of the movie from static images.
Normally use |
transparent |
A string. The color recognized as a background
and made to be transparent in animated gif output.
If not set, all the images are used without transparency.
Ignored when using |
verbose |
A logical. Whether to print detailed output from the converting command into R's terminal. |
When analyzing the data, there are often cases
you want to visualize your result in animated movie clips
rather than static graphics like eps or png.
htbPlotAnim()
provides an easy way to such dynamic graphical outputs.
Since R intrinsically does not have built-in dynamic graphics,
this function achieves it by virtue of
external software such as ffmpeg
or convert (ImageMagic)
.
By just designing the size of the output
along with a set of R codes to plot multiple sequential static images,
htbPlotAnim()
puts out those images as temporal files
and concatenates them into a movie clip.
Static images are then automatically removed,
thus no garbage files are left behind.
If corresponding terminal command (ffmpeg
for mp4 and convert
for gif)
is not available,
htbPlotAnim()
cannot compile a movie and prints an error.
In such a case, please install the required software
and make sure it is executable.
(Management of environmental variable may be needed for Windows users.)
Alternatively, you can explicitly designate a full path
to the converting command by converter
argument.
Be careful, however, because
consistency between output file type and the converting command
is not verified in this case.
## Not run:
n <- 150
w0 <- cumsum(rnorm(n, mean = 0))
w1 <- cumsum(rnorm(n, mean = 0.2))
htbPlotAnim("randomwalk.mp4", 320, 240, {
par(mar = c(3, 3, 1, 1), las = 1)
for (i in 1:n) {
j <- 1:i
blankplot(xlim = c(0, i), ylim = range(c(w0[j], w1[j])))
lines(j, w0[j], lty = "22")
lines(j, w1[j], lwd = 2)
}
}, fps = 15)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.