gg_animate

0th

Percentile

Show an animation of a ggplot2 object

Show an animation of a ggplot2 object that contains a frame aesthetic. This frame aesthetic will determine which frame the animation is shown in. For example, you could add the aesthetic frame = time to a dataset including a time variable. Each distinct value of the frame aesthetic is rendered into one frame of the resulting animation, in sorted order.

Usage
gg_animate(p = last_plot(), filename = NULL, saver = NULL, title_frame = TRUE, ...)
Arguments
p
A ggplot2 object. If no plot is provided, use the last plot by default.
filename
Optionally, an output file to save to. If not given, will store as plots without (yet) saving to a file
saver
A string such as "mp4" or "gif" that specifies a function from the animation package such as saveVideo or saveGIF to use for saving. This can also be recognized from the filename extension.
title_frame
Whether to title each image with the current frame value. The value is appended on to any existing title.
...
If saving to a file, extra arguments to pass along to the animation saving function (to saveVideo/saveGIF/etc).
Details

If cumulative = TRUE is set within a layer along with a frame aesthetic, the frames build cumulatively rather than each being generated with separate data.

Aliases
  • gg_animate
Examples

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)


Documentation reproduced from package gganimate, version 0.1, License: GPL-2

Community examples

Looks like there are no examples yet.