library(ggplot2)
library(gapminder)
p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
geom_point() +
scale_x_log10()
p
gganimate(p)
## Not run:
# gganimate(p, "output.gif")
# gganimate(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()
gganimate(p2, title_frame = FALSE)
Run the code above in your browser using DataLab