Skip to content

Instantly share code, notes, and snippets.

@gonzalezgouveia
Last active February 28, 2019 19:16
Show Gist options
  • Save gonzalezgouveia/a6c93e8b006cd950792a3d887463e45c to your computer and use it in GitHub Desktop.
Save gonzalezgouveia/a6c93e8b006cd950792a3d887463e45c to your computer and use it in GitHub Desktop.
# install.packages(gganimate)
library(gganimate)
# devtools::install_github('rensa/ggflags')
library(ggflags)
# install.packages("gifski")
library(gifski)
# define animation object
anim <- gapminder_hispam %>%
filter(year >= 1900) %>%
ggplot(aes(x = log_gdppc, y = lifeExp, country = code)) +
theme(text = element_text(size=20)) +
ylim(10,90) +
scale_x_continuous(breaks = c(2,3,4),
labels = c("$400","$4 000","$40 000"),
limits = c(2,4.1)) +
geom_flag(size = 10) +
transition_states(year, transition_length = 1, state_length = 1) +
ylab('Años de vida') +
xlab('Ingreso por persona (USD)') +
ggtitle('Ahora mostrando año {closest_state}')
# animate it
animate(anim,
width = 400, height = 400,
nframes = 480, fps = 24)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment