Last active
January 16, 2021 13:44
-
-
Save tanerumit/71cefed81dc86d609afdf0637068bad6 to your computer and use it in GitHub Desktop.
#ggplot #R #example for animated gifs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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