Learn R Programming

animation (version 1.1-4)

saveLatex: Insert animations into a LaTeX document and compile it.

Description

Insert animations into a LaTeX document and compile it. Record animation frames and insert them into a LaTeX document with the animate package. Compile the document if an appropriate LaTeX command is provided.

Usage

saveLatex(expr, interval=ani.options("interval"),
    nmax=ani.options("nmax"), ani.dev="pdf",
    outdir=ani.options("outdir"), ani.basename="Rplot", ani.ext="pdf",
    num=ifelse(ani.ext == "pdf", "", "%d"), ani.first=par(), ani.opts,
    centering, caption, label, pkg.opts, documentclass="article",
    latex.filename="animation.tex", pdflatex="pdflatex",
    install.animate=TRUE, ...)

Arguments

expr
an expression to generate animations; use either the animation functions (e.g. brownian.motion()) 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)
nmax,outdir
maximum number of animatio frames and the directory for output (see ani.options)
ani.dev
the graphics device to be used to record image frames
ani.basename,ani.ext
basename and extension of file names of animation frames
num
the format for page numbers
ani.first
an expression to be evaluated before plotting (this will be useful to set graphical parameters in advance, e.g. ani.first = par(pch = 20))
ani.opts
options to control the behavior of the animation (passed to the LaTeX macro "\animategraphics"; default to be "controls,width=\textwidth")
centering
the macro to center the graph (can be NULL; default to be "\centering")
caption,label
caption and label for the graphics in the figure environment
pkg.opts
global options for the animate package
documentclass
LaTeX document class
latex.filename
file name of the LaTeX document; if an empty string "", the LaTeX code will be printed in the console and hence not compiled
pdflatex
the command for pdfLaTeX (set to NULL to ignore the compiling)
install.animate
copy the LaTeX style files animate.sty and animfp.sty to outdir? If you have not installed the LaTeX package animate, it suffices just to copy these to files.
...
other arguments passed to the graphics device ani.dev, e.g. height and width

Value

  • Invisible NULL

Details

This is actually a wrapper to generate a LaTeX document using R. The document uses the LaTeX package called animate to insert animations into PDF's. When we pass an R expression to this function, the expression will be evaluated and recorded by a grahpics device (typically png and pdf). At last, a LaTeX document will be created and compiled if an appropriate LaTeX command is provided. And the final PDF output will be opened with the PDF viewer set in getOption("pdfviewer") if ani.options("autobrowse") == TRUE.

References

To know more about the animate package, please refer to http://www.ctan.org/tex-archive/macros/latex/contrib/animate/. There are a lot of options can be set in ani.opts and pkg.opts.

See Also

saveMovie to convert image frames to a single GIF/MPEG file; saveSWF to convert images to Flash; ani.start and ani.stop to create an HTML page containing the animation

Examples

Run this code
oopt = ani.options(interval = 0.1, nmax = 100)
## brownian motion: note the 'loop' option in ani.opts
##     and how to set graphics parameters with 'ani.first'
saveLatex({
brownian.motion(pch = 21, cex = 5, col = "red", bg = "yellow",
main = "Demonstration of Brownian Motion")
}, ani.basename = "BM", ani.opts = "controls,loop,width=0.8\\textwidth",
ani.first = par(mar = c(3, 3, 1, 0.5), mgp = c(2, 0.5, 0),
tcl = -0.3, cex.axis = 0.8, cex.lab = 0.8, cex.main = 1),
latex.filename = "brownian.motion.tex")
ani.options(oopt)

Run the code above in your browser using DataLab