Created
March 11, 2010 18:58
-
-
Save HarlanH/329514 to your computer and use it in GitHub Desktop.
demonstration of animating R/ggplot2 graphs with ImageMagick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NOTE: requires ImageMagick to be installed and in the PATH! Should work on most Linux and Mac systems. | |
library(ggplot2) | |
d <- data.frame(x=rep(1:10,10), y=rnorm(100, 1:10)) | |
files <- character() | |
for (i in 1:10) | |
{ | |
p <- ggplot(subset(d, subset=x<=i), aes(x=x, y=y)) + geom_point() + | |
scale_x_continuous(limits=c(0,11)) + scale_y_continuous(limits=c(0,11)) | |
ggsave(filename=(files[i]=sprintf("frame%03d.png", i)), plot=p) | |
} | |
cmd <- paste("convert -delay 100", paste(files, collapse=" "), "animated.gif") | |
system(cmd) | |
file.remove(unlist(files)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment