Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@johnburnmurdoch
Created October 26, 2018 17:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnburnmurdoch/cb7a7286abb1c1643fe43442eed6225c to your computer and use it in GitHub Desktop.
Save johnburnmurdoch/cb7a7286abb1c1643fe43442eed6225c to your computer and use it in GitHub Desktop.
# Data is the UN's Medium-variant population projections, available at https://population.un.org/wpp/
data %>%
filter(Sex != "Both" & A3 %in% c("GBR", "RUS", "IND", "CHN", "RWA", "GRC") & Year %in% 2018:2060) %>%
as.tibble %>%
mutate(
group = paste0(Year, Sex), AgeGrp = as.numeric(AgeGrp),
Location = Location %>% gsub("n Federation","",.)
) %>%
ggplot(aes(AgeGrp, Value, col=Sex, group=group)) +
theme_minimal() +
theme(
text = element_text(family = "Avenir"),
axis.text = element_blank(),
strip.text = element_blank(),
legend.position = c(0,1),
legend.justification = c(0,0.6),
legend.margin = margin(0,0,0,0,"cm"),
legend.title = element_blank(),
legend.direction = "horizontal",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.caption = element_text(hjust=0)
) +
geom_line(aes(alpha=Year)) +
geom_text(data = . %>% filter(Year == 2050 & Sex == "Female" & AgeGrp == 0), aes(label=Location, y=Value*0.8), hjust=0, col="#212121", size=textSizer(14)) +
scale_y_continuous(labels=comma_format()) +
labs(x = "", y= "", title = "Population curves", caption="@jburnmurdoch") +
facet_wrap(~Location, scales="free_y") +
scale_color_manual(values = FT.palettes$categorical_line[c(1,3)], guide=guide_legend(title="")) +
scale_alpha_continuous(guide=F)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment