I think you can do this also with the write.gif function in the caTools library. You'd have to get your graph into a multi-frame image first. I'm not sure how to do that. Anyone? Bueller?
The classic example of an animated GIF is this code which I didn't write but I did blog about some time ago:
library(fields) # for tim.colors
library(caTools) # for write.gif
m = 400 # grid size
C = complex( real=rep(seq(-1.8,0.6, length.out=m), each=m ), imag=rep(seq(-1.2,1.2, length.out=m), m ) )
C = matrix(C,m,m)
Z = 0
X = array(0, c(m,m,20))
for (k in 1:20) {
Z = Z^2+C
X[,,k] = exp(-abs(Z))
}
image(X[,,k], col=tim.colors(256)) # show final image in R
write.gif(X, 'Mandelbrot.gif', col=tim.colors(256), delay=100)
Code credit goes to Jarek Tuszynski, PhD.