frameaesthetic will determine which frame the animation is shown in. For example, you could add the aesthetic
frame = timeto a dataset including a
timevariable. Each distinct value of the frame aesthetic is rendered into one frame of the resulting animation, in sorted order.
gg_animate(p = last_plot(), filename = NULL, saver = NULL, title_frame = TRUE, ...)
saveGIFto use for saving. This can also be recognized from the filename extension.
framevalue. The value is appended on to any existing title.
cumulative = TRUEis set within a layer along with a
frameaesthetic, the frames build cumulatively rather than each being generated with separate data.
library(ggplot2) library(gapminder) p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) + geom_point() + scale_x_log10() p gg_animate(p) ## Not run: # gg_animate(p, "output.gif") # gg_animate(p, "output.mp4") # ## End(Not run) # You can also create cumulative graphs by adding the `cumulative = TRUE` aesthetic. # For example, we could show the progression of temperature over time. aq <- airquality aq$date <- as.Date(paste(1973, aq$Month, aq$Day, sep = "-")) p2 <- ggplot(aq, aes(date, Temp, frame = Month, cumulative = TRUE)) + geom_line() gg_animate(p2, pause = .5, title_frame = FALSE)