Learn R Programming

animation (version 1.1-4)

animation-package: Statistical Animations Using R.

Description

Statistical Animations Using R. Various functions for animations in statistics which could probably aid in teaching statistics and data analysis.

Arguments

Details

ll{ Package: animation Type: Package Version: 1.1 Date: 2010-09-28 License: GPL-2 | GPL-3 } This package mainly makes use of HTML & JavaScript and R windows graphics devices (such as x11) to demonstrate animations in statistics; other kinds of output such as Flash (SWF) or GIF animations or PDF animations are also available if required software packages have been installed.

References

AniWiki: Animations in Statistics http://animation.yihui.name

Examples

Run this code
#############################################################
# (1) Animations in HTML pages
# create an animation page in the tempdir() and auto-browse it
# Brownian Motion
oopt = ani.options(interval = 0.05, nmax = 100, ani.dev = png,
ani.type = "png",
title = "Demonstration of Brownian Motion",
description = "Random walk on the 2D plane: for each point
(x, y), x = x + rnorm(1) and y = y + rnorm(1).")
ani.start()
opar = par(mar = c(3, 3, 2, 0.5), mgp = c(2, .5, 0), tcl = -0.3,
cex.axis = 0.8, cex.lab = 0.8, cex.main = 1)
brownian.motion(pch = 21, cex = 5, col = "red", bg = "yellow",
main = "Demonstration of Brownian Motion")
par(opar)
ani.stop()
ani.options(oopt)

#############################################################
# (2) Animations inside R windows graphics devices
# Bootstrapping
oopt = ani.options(interval = 0.3, nmax = 50)
boot.iid()
ani.options(oopt)

#############################################################
# (3) GIF animations
oopt = ani.options(interval = 0, nmax = 100)
saveMovie(brownian.motion(pch = 21, cex = 5, col = "red", bg = "yellow"),
interval = 0.05, outdir = getwd(), width = 600, height = 600)
ani.options(oopt)

#############################################################
# (4) Flash animations
oopt = ani.options(nmax = 100, interval = 0)
saveSWF(buffon.needle(type = "S"), para = list(mar = c(3, 2.5, 1, 0.2),
pch = 20, mgp = c(1.5, 0.5, 0)), dev = "pdf", swfname = "buffon.swf",
outdir = getwd(), interval = 0.1)
ani.options(oopt)

#############################################################
# (5) PDF animations
oopt = ani.options(interval = 0.1, nmax = 100)
saveLatex({
brownian.motion(pch = 21, cex = 5, col = "red", bg = "yellow",
main = "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