Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Making an Animation

Create 10 files of jpg

frames <- 10
for(i in 1:frames) 
{
  jpeg(sprintf("ani_%02d.jpg", i))
  plot(1:10, 1:10, col=i)
  dev.off()
}

Then use ImageMagick to transform to an animated gif:

system("convert -delay 10 ani_??.jpg animation.gif")



> ##
> install.packages("animation")
> library(animation)
> # default animation in R: with slope changing
> least.squares()
> # animation in an HTML page
> oopt = ani.options(ani.height = 450, ani.width = 600,
      outdir = tempdir(), nmax = 50, title = "Demonstration of Least Squares",
      description = "We want to find an estimate for the slope
           in 50 candidate slopes, so we just compute the RSS one by one. ")
> ani.start()
> par(mar = c(4, 4, 0.5, 0.1), mgp = c(2, 0.5, 0), tcl = -0.3)
> least.squares()
> ani.stop()
> ani.options(oopt)



Copyright © Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
The PDF version is a formatted comprehensive draft book (with over 800 pages).
Brought to you by Togaware. This page generated: Sunday, 22 August 2010