-
Notifications
You must be signed in to change notification settings - Fork 310
Gapminder
submitted by thomasp85
One of the most impactful dataviz animations was made by Hans Rosling (video), in where he shows the development in life expectancy and a countries GDP per capita through roughly the last half of the 20th century.
The impact of the animation does not come from any complexity, but from the story it tells and how well Hans Rosling uses it to communicate the implications of it. This underscores that the goal of animations are not (only) to wow the audience, but to support communication and learning.
library(gapminder)
library(ggplot2)
library(gganimate)
ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = country)) +
geom_point(alpha = 0.7) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
facet_wrap(~continent) +
theme(legend.position = 'none') +
labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
transition_time(year)
In this example we depart from the original by introducing faceting in order to more clearly separate the different continents and allow for a better assessment of how the develop as a whole. The animation part is pretty simple - we use transition_time()
as the animation flows along a continuous time scale. Further we set easing to be linear with ease_aes()
to avoid putting emphasis on specific time points. In order to identify the time scale of the animation we use the frame_time
frame variable in the plot title to update the title to match the current year.
Install gganimate using devtools::install_github('thomasp85/gganimate')
The Grammar
Misc
Examples