The gganimate package
2025-10-16
An intro to gganimate
An intro to gganimate
gapminder |>
ggplot(aes(x = gdpPercap, y = lifeExp, size = pop, color = country)) +
geom_point(alpha = 0.7, show.legend = FALSE) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
facet_wrap(~ continent) +
labs(
x = "GDP per capita",
y = "life expectancy"
)# may need to make sure gifski and av packages are installed!
gapminder |>
ggplot(aes(x = gdpPercap, y = lifeExp, size = pop, color = country)) +
geom_point(alpha = 0.7, show.legend = FALSE) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
facet_wrap(~ continent) +
transition_time(year) +
ease_aes('linear') +
labs(
title = "Year: {frame_time}",
x = "GDP per capita",
y = "life expectancy"
)Learn more: Code Animations
# may need to make sure gifski and av packages are installed!
gapminder |>
ggplot(aes(x = gdpPercap, y = lifeExp, size = pop, color = country)) +
geom_point(alpha = 0.7, show.legend = FALSE) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
facet_wrap(~ continent) +
transition_time(year) +
ease_aes('linear') +
labs(
title = "Year: {frame_time}",
x = "GDP per capita",
y = "life expectancy"
)Learn more: Line Highlighting
Learn more: Executable Code
gapminder |>
ggplot(aes(x = lifeExp, y = continent, fill = continent)) +
geom_density_ridges(show.legend = FALSE, alpha = 0.5) +
labs(
title = "Life Expectancy by Continent",
subtitle = "Year: {frame_time}",
x = "Life Expectancy",
y = "Continent"
) +
transition_time(year) +
ease_aes("linear")Learn more: Code Animations
gapminder |>
ggplot(aes(x = lifeExp, y = continent, fill = continent)) +
geom_density_ridges(show.legend = FALSE, alpha = 0.5) +
labs(
title = "Life Expectancy by Continent",
subtitle = "Year: {frame_time}",
x = "Life Expectancy",
y = "Continent"
) +
transition_time(year) +
ease_aes("linear")Learn more: Line Highlighting
Learn more: Executable Code
Lists can optionally be displayed incrementally:
Learn more: Incremental Lists
Thanks to Jenna Graff of MSCS 264 in Spring 2024 for putting together the original powerpoint presentation on gganimate. Here’s a link with even more information:
Learn more: Preview Links