Skip to content

Instantly share code, notes, and snippets.

@walkerke
Created April 12, 2021 13:51
Show Gist options
  • Save walkerke/b67aae92d10ed6a20df691e48bfc1d27 to your computer and use it in GitHub Desktop.
Save walkerke/b67aae92d10ed6a20df691e48bfc1d27 to your computer and use it in GitHub Desktop.
library(idbr)
library(tidyverse)
library(gganimate)
france_data <- get_idb(
country = "France",
year = 1990:2021,
age = 0:100,
sex = c("male", "female")
)
pyramid <- france_data %>%
mutate(pop = ifelse(sex == "Male", pop * -1, pop)) %>%
ggplot(aes(x = pop, y = as.factor(age), fill = sex)) +
geom_col(width = 1) +
theme_minimal(base_size = 15) +
scale_x_continuous(labels = function(x) paste0(abs(x / 1000000), "m")) +
scale_y_discrete(breaks = scales::pretty_breaks(n = 10)) +
scale_fill_manual(values = c("red", "blue")) +
transition_states(year) +
labs(title = "Population structure of France in {closest_state}",
x = "Population",
y = "Age",
fill = "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment