#LyX 1.6.7 created this file. For more info see http://www.lyx.org/ \lyxformat 345 \begin_document \begin_header \textclass literate-beamer \begin_preamble \usepackage[buttonsize=1em]{animate} \end_preamble \use_default_options true \language english \inputencoding auto \font_roman default \font_sans default \font_typewriter default \font_default_family default \font_sc false \font_osf false \font_sf_scale 100 \font_tt_scale 100 \graphics default \paperfontsize default \spacing single \use_hyperref false \papersize default \use_geometry true \use_amsmath 1 \use_esint 1 \cite_engine basic \use_bibtopic false \paperorientation portrait \secnumdepth 3 \tocdepth 3 \paragraph_separation indent \defskip medskip \quotes_language english \papercolumns 1 \papersides 1 \paperpagestyle default \tracking_changes false \output_changes false \author "" \author "" \end_header \begin_body \begin_layout Standard \begin_inset Flex Sweave Options status open \begin_layout Plain Layout eps=FALSE,pdf=FALSE,tidy=TRUE,external=TRUE,prefix.string=Rfig \end_layout \end_inset \end_layout \begin_layout Scrap <>= \end_layout \begin_layout Scrap options(prompt=' ',continue=' ') \end_layout \begin_layout Scrap @ \end_layout \begin_layout Title New Features and Enhancements of the \family typewriter animation \family default Package \end_layout \begin_layout Author Yihui Xie \end_layout \begin_layout Institute Department of Statistics, Iowa State University \end_layout \begin_layout BeginFrame The winter break \end_layout \begin_layout Itemize nice weather in Ames \end_layout \begin_layout Itemize + my limited driving skills \begin_inset Formula $\Rightarrow$ \end_inset \end_layout \begin_layout Pause \end_layout \begin_layout Itemize substantial updates to the \family typewriter animation \family default package \end_layout \begin_layout Itemize see GitHub: \begin_inset Flex URL status open \begin_layout Plain Layout https://github.com/yihui/animation/graphs/impact \end_layout \end_inset \end_layout \begin_layout EndFrame \end_layout \begin_layout BeginFrame Introduction \end_layout \begin_layout Itemize a package for fun \end_layout \begin_layout Itemize very naive ideas! (see the basic schema later) \end_layout \begin_layout Itemize to escape the world of \begin_inset Formula $\alpha,\beta,\gamma$ \end_inset ... but who knows... \end_layout \begin_layout Pause \end_layout \begin_layout Itemize it won the John Chambers Software award in 2009 \end_layout \begin_deeper \begin_layout Itemize felt as if I won the lottery \end_layout \begin_layout Itemize it turned out that... :-( \end_layout \end_deeper \begin_layout Pause \end_layout \begin_layout Itemize seriously, people are \emph on using \emph default this package! (feedback from old friends, teachers, ...) \end_layout \begin_layout Pause \end_layout \begin_layout Itemize are all these a joke?! \end_layout \begin_layout EndFrame \end_layout \begin_layout Standard \begin_inset Flex Flex:FragileFrame status open \begin_layout Plain Layout \begin_inset Flex Flex:FragileTitle status open \begin_layout Plain Layout The Holy Truth \end_layout \end_inset \end_layout \begin_layout Scrap <>= \end_layout \begin_layout Scrap ## set some options first \end_layout \begin_layout Scrap ani.options(interval = 0.2, nmax = 10) \end_layout \begin_layout Scrap ## use a loop to create plots one by one \end_layout \begin_layout Scrap for (i in 1:ani.options("nmax")) { \end_layout \begin_layout Scrap draw_plot() # may need calculations beforehand \end_layout \begin_layout Scrap ani.pause() # pause for a while \end_layout \begin_layout Scrap } \end_layout \begin_layout Scrap ## that's it! \end_layout \begin_layout Scrap @ \end_layout \end_inset \end_layout \begin_layout EndFrame \end_layout \begin_layout BeginFrame The rest of things \end_layout \begin_layout Itemize once you know the holy truth, there is only one thing to do \end_layout \begin_layout Pause \end_layout \begin_layout Itemize programming like crazy, using as wild imagination as possible \end_layout \begin_layout Itemize looks like \begin_inset Quotes eld \end_inset labor work \begin_inset Quotes erd \end_inset \end_layout \begin_layout EndFrame \end_layout \begin_layout Standard \begin_inset Flex Flex:FragileFrame status open \begin_layout Plain Layout \begin_inset Flex Flex:FragileTitle status open \begin_layout Plain Layout A dirty example \end_layout \end_inset \end_layout \begin_layout Scrap <>= \end_layout \begin_layout Scrap library(animation) \end_layout \begin_layout Scrap brownian.motion \end_layout \begin_layout Scrap @ \end_layout \end_inset \end_layout \begin_layout BeginFrame Standing on the shoulders of giants \end_layout \begin_layout Itemize none of the exporting utilites is really my contribution, except the first version of the HTML animations \end_layout \begin_layout Itemize the workhorses: \end_layout \begin_deeper \begin_layout Itemize \family typewriter saveHTML() \family default -- using SciAnimator (a JS library I found right before I started to rewrite my JavaScript) \end_layout \begin_layout Itemize \family typewriter saveGIF() \family default -- using GraphicsMagick or ImageMagick \end_layout \begin_layout Itemize \family typewriter saveSWF() \family default -- using SWF Tools \end_layout \begin_layout Itemize \family typewriter saveLatex() \family default -- using the LaTeX package \family typewriter animate \end_layout \begin_layout Itemize \family typewriter saveVideo() \family default -- using FFmpeg \end_layout \end_deeper \begin_layout EndFrame \end_layout \begin_layout BeginFrame HTML pages \end_layout \begin_layout Itemize this approach does not require additional software; a web browser is enough \end_layout \begin_layout Itemize give me a code chunk to produce plots, and I'll return you a web page with animations \end_layout \begin_layout EndFrame \end_layout \begin_layout Standard \begin_inset Flex Flex:FragileFrame status open \begin_layout Plain Layout \begin_inset Flex Flex:FragileTitle status open \begin_layout Plain Layout saveHTML() \end_layout \end_inset \end_layout \begin_layout Scrap <>= \end_layout \begin_layout Scrap saveHTML({ \end_layout \begin_layout Scrap par(mar = c(4, 4, 0.5, 0.5)) \end_layout \begin_layout Scrap for (i in 1:20) { \end_layout \begin_layout Scrap plot(runif(20), ylim = c(0, 1)) \end_layout \begin_layout Scrap ani.pause() \end_layout \begin_layout Scrap } \end_layout \begin_layout Scrap }, img.name = "unif_plot", htmlfile = "random.html") \end_layout \begin_layout Scrap @ \end_layout \end_inset \end_layout \begin_layout BeginFrame The interface in the HTML page \end_layout \begin_layout Itemize like a movie player (written in JavaScript) \end_layout \begin_layout Itemize see the \family typewriter quincunx() \family default example (change the loop mode and you will find real fun!) \end_layout \begin_layout EndFrame \end_layout \begin_layout BeginFrame A crazy extension: Rweb \end_layout \begin_layout Itemize \family typewriter saveHTML() \family default is so flexible that you can submit some R code to a server, and it will immediately generate the animation for you! \end_layout \begin_layout Itemize see \family typewriter system.file('misc', 'Rweb', 'demo.html', package = 'animation') \end_layout \begin_layout Itemize this feature is experimental (subject to the server admin) \end_layout \begin_layout EndFrame \end_layout \begin_layout BeginFrame saveGIF(), saveSWF(), saveVideo() \end_layout \begin_layout Itemize they require additional software packages \end_layout \begin_layout Itemize similar usage to \family typewriter saveHTML() \end_layout \begin_layout Itemize did really hard work under the all-mighty Windows system \end_layout \begin_layout EndFrame \end_layout \begin_layout BeginFrame saveLatex() \end_layout \begin_layout Itemize this package was listed in the CRAN Task View \begin_inset Quotes eld \end_inset ReproducibleResearch \begin_inset Quotes erd \end_inset \emph on before \emph default it is really prepared to be listed there! \end_layout \begin_deeper \begin_layout Itemize why things always come earlier than I expected? \end_layout \end_deeper \begin_layout Itemize \begin_inset Flex URL status open \begin_layout Plain Layout http://cran.r-project.org/web/views/ReproducibleResearch.html \end_layout \end_inset \end_layout \begin_layout Itemize so \family typewriter saveLatex() \family default was updated to incorporate with Sweave for reproducible research \end_layout \begin_layout Itemize it was originally written to insert animations in LaTeX documents only, using a LaTeX package \family typewriter animate \end_layout \begin_layout Itemize see \family typewriter demo('Sweave_animation', package = 'animation') \end_layout \begin_layout Itemize we can watch PDF animations only with Adobe Reader \end_layout \begin_layout EndFrame \end_layout \begin_layout BeginFrame Another crazy extension \end_layout \begin_layout Itemize we can capture arbitrary animations in LaTeX with \family typewriter saveLaTeX() \family default (in fact, with any \family typewriter save*() \family default functions) \end_layout \begin_layout Itemize e.g. the \family typewriter rgl \family default 3D animations \end_layout \begin_layout Itemize \family typewriter demo('rgl_animation', package = 'animation') \end_layout \begin_layout EndFrame \end_layout \begin_layout BeginFrame Yet another crazy extension \end_layout \begin_layout Itemize we can download images from the internet and create an animation \end_layout \begin_layout Itemize \family typewriter demo('flowers', package = 'animation') \family default shows some flower photos I took a few years ago \end_layout \begin_layout EndFrame \end_layout \begin_layout BeginFrame A gory detail that puzzled me for years \end_layout \begin_layout Itemize low-level plotting functions in base graphics cannot be recorded by R graphics devices as new images \end_layout \begin_layout Itemize e.g. add points one by one to a plot -- you only get one image file under a \family typewriter png() \family default device \end_layout \begin_layout Itemize this brings us ugly solutions -- redraw the whole plot in order to be recorded \end_layout \begin_layout Itemize now we have a new solution \end_layout \begin_layout EndFrame \end_layout \begin_layout BeginFrame The animation recorder \end_layout \begin_layout Itemize R graphics can be recorded by \family typewriter recordPlot() \family default (as a list) \end_layout \begin_layout Itemize and the recorded plot can be replayed \end_layout \begin_layout Itemize \family typewriter ani.record() \family default and \family typewriter ani.replay() \family default extended these functions a little bit, so we can record a sequence of images and replay later \end_layout \begin_layout EndFrame \end_layout \begin_layout Standard \begin_inset Flex Flex:FragileFrame status open \begin_layout Plain Layout \begin_inset Flex Flex:FragileTitle status open \begin_layout Plain Layout An example of the recorder \end_layout \end_inset \end_layout \begin_layout Scrap <>= \end_layout \begin_layout Scrap library(animation) \end_layout \begin_layout Scrap n = 20 \end_layout \begin_layout Scrap x = sort(rnorm(n)) \end_layout \begin_layout Scrap y = rnorm(n) \end_layout \begin_layout Scrap ## set up an empty frame; add points one by one \end_layout \begin_layout Scrap plot(x, y, type = "n") \end_layout \begin_layout Scrap ani.record(reset = TRUE) # clear history first \end_layout \begin_layout Scrap for (i in 1:n) { \end_layout \begin_layout Scrap points(x[i], y[i], pch = 19, cex = 2) \end_layout \begin_layout Scrap ani.record() # record the current frame \end_layout \begin_layout Scrap } \end_layout \begin_layout Scrap ani.options(interval = 0.5) \end_layout \begin_layout Scrap ani.replay() \end_layout \begin_layout Scrap @ \end_layout \end_inset \end_layout \begin_layout BeginFrame Topics in statistics \end_layout \begin_layout Itemize the bisection method, the gradient descent algorithm, Newton-Raphson \end_layout \begin_layout Itemize Brownian motion \end_layout \begin_layout Itemize bootstrapping, cross-validation \end_layout \begin_layout Itemize Buffon's needle \end_layout \begin_layout Itemize CLT, LLN \end_layout \begin_layout Itemize flipping coins \end_layout \begin_layout Itemize least squares \end_layout \begin_layout Itemize k-Means clustering, k-Nearest neighbors \end_layout \begin_layout Itemize survey sampling methods \end_layout \begin_layout Itemize simulating QQ plots \end_layout \begin_layout Itemize Monte Carlo integration \end_layout \begin_layout Itemize (see the JSS manuscript for examples) \end_layout \begin_layout EndFrame \end_layout \begin_layout BeginFrame Demo! \end_layout \begin_layout Itemize see \family typewriter demo(package = 'animation') \end_layout \begin_layout Itemize some are amusing and entertaining \end_layout \begin_layout Itemize let's watch a few of them \end_layout \begin_deeper \begin_layout Itemize the NBA game \end_layout \begin_layout Itemize Mandelbrot set \end_layout \begin_layout Itemize Xmas, Xmas2, Xmas_card \end_layout \begin_layout Itemize busybees: in memory of my childhood \end_layout \begin_layout Itemize simulating the fire \end_layout \begin_layout Itemize the Game of Life (cat faces?) \end_layout \begin_layout Itemize Tower of Hanoi \end_layout \begin_layout Itemize the Jumping Horse \end_layout \end_deeper \begin_layout EndFrame \end_layout \begin_layout BeginFrame Final notes \end_layout \begin_layout Itemize this talk is based on animation 2.0-2, which is not released to CRAN yet, but most things should work \end_layout \begin_layout Itemize if you are really brave and eager to follow the latest version, go to \begin_inset Flex URL status open \begin_layout Plain Layout https://github.com/yihui/animation \end_layout \end_inset \end_layout \begin_layout Itemize otherwise \family typewriter install.packages('animation') \end_layout \begin_layout Itemize a web collection of animations: \begin_inset Flex URL status open \begin_layout Plain Layout http://animation.yihui.name \end_layout \end_inset \end_layout \begin_layout EndFrame \end_layout \begin_layout BeginFrame Conclusions \end_layout \begin_layout Itemize finally I feel less guilty for winning the Chambers award \end_layout \begin_layout Pause \end_layout \begin_layout Itemize life should be fun \end_layout \begin_layout Pause \end_layout \begin_layout Itemize seriously speaking, I think we are too serious \end_layout \begin_layout Itemize looking forward to more alive statistical reports! \end_layout \begin_layout EndFrame \end_layout \end_body \end_document