if(require(ggplot2) & interactive()){
gg_record(dir = file.path(tempdir(),"recording"))
ggplot(data.frame(x = 1, y = 1), aes(x=x, y=y)) + geom_point() + ylim(0,4)
ggplot(data.frame(x = 1, y = 2), aes(x=x, y=y)) + geom_point() + ylim(0,4)
## resize canvas of the last plot
gg_resize_film(height = 10, width = 5, dpi = 350)
ggplot(data.frame(x = 1, y = 3), aes(x=x, y=y)) + geom_point() + ylim(0,4)
gg_playback(tempfile(fileext = ".gif"))
}
Run the code above in your browser using DataLab