Here is my first use of the animation package. It was easier than I expected, and especially saveHTML really awesome. Here is my scenario (even I think my R code will be clearer :)
- I am generating some data
- I draw the main plot for all people as a wallpaper.
- I modify the data to get to a wide format so that I can build an arrow between the current and next position for each person.
- I loop through the clock to generate many stories. I put llop in the powerful
saveHTML function. - You get an html file with nice animation. I am showing here one interim plot.

Here is my code:
library(animation) library(ggplot2) library(grid) ## creating some data of hours N.hour <- 24 dat <- data.frame(person=rep(paste0('p',1:3),N.hour), lat=sample(1:10,3*N.hour,rep=TRUE), long=sample(1:10,3*N.hour,rep=TRUE), time=rep(1:N.hour,each=3)) # the base plot with base <- ggplot() + geom_point(data=dat,aes(x=lat, y=long,colour = person), size=5)+ theme(legend.position = "none") ## reshape data to lat and long formats library(plyr) dat.segs <- ddply(dat,.(person),function(x){ dd <- do.call(rbind, lapply(seq(N.hour-1), function(y)c(y,x[x$time %in% c(y,y+1),]$lat, x[x$time %in% c(y,y+1),]$long))) dd }) colnames(dat.segs) <- c('person','path','x1','x2','y1','y2') # a function to create the animation oopt <- ani.options(interval = 0.5) saveHTML({ print(base) interval = ani.options("interval") for(hour in seq(N.hour-1)){ # a segment for each time tn <- geom_segment(aes(x= x1, y= y1, xend = x2, yend = y2,colour = person), arrow = arrow(), inherit.aes = FALSE, data =subset(dat.segs,path==hour)) print(base <- base + tn) ani.pause() } }, img.name = "plots", imgdir = "plots_dir", htmlfile = "random.html", autobrowse = FALSE, title = "Demo of animated lat/long for different persons", outdir=getwd())