Skip to content

Instantly share code, notes, and snippets.

@tanerumit
Last active January 16, 2021 13:44
Show Gist options
  • Save tanerumit/71cefed81dc86d609afdf0637068bad6 to your computer and use it in GitHub Desktop.
Save tanerumit/71cefed81dc86d609afdf0637068bad6 to your computer and use it in GitHub Desktop.
#ggplot #R #example for animated gifs
library(tidyverse)
library(gganimate)
## standard ggplot2
myPlot <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = country)) +
geom_point(alpha = 0.7, show.legend = FALSE) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
# Here comes the gganimate specific bits
labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
transition_time(year) +
ease_aes('linear')
animate(myPlot, duration = 5, fps = 20, width = 200, height = 200, renderer = gifski_renderer())
anim_save("output.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment