Extras

Kieran Healy

Duke University

April 17, 2024

Extras

Load our packages

library(here)       # manage file paths
library(tidyverse)  # your friend and mine
library(socviz)     # data and some useful functions
library(ggrepel)    # Text and labels
library(colorspace) # luminance-balanced palettes
library(scales)      # scale adjustments and enhancements
library(ggforce)    # useful enhancements to ggplot

## install.packages("gifski")
## install.packages("gganimate")

library(gapminder)
library(gganimate) # Animation

Gapminder returns

p <- ggplot(data = gapminder, 
            mapping = aes(x = gdpPercap, y=lifeExp, 
                          size = pop, color = country)) +
  geom_point(show.legend = FALSE, alpha = 0.7) +
  scale_color_viridis_d() +
  scale_size(range = c(2, 12)) +
  scale_x_log10() +
  labs(x = "GDP per capita", y = "Life expectancy")

p

Gapminder returns

But add one thing

p_live <- p + transition_time(year) +
  labs(title = "Year: {frame_time}")
animate(p_live, renderer = ffmpeg_renderer())

But add one thing