knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
Download past and current versions of the UN DESA World Population Prospects data into R. See the pkgdown site for full details.
Install the developmental version with:
library(devtools) install_github("guyabel/tidywpp", ref = "main")
Data downloaded using tidywpp is in tidy form, and hence does not require any major manipulations for use in popular modelling and visualisation functions in R.
library(tidywpp) d <- get_wpp(indicator = "pop", pop_age = "single", pop_sex = "both", tidy_pop_sex = TRUE, drop_id_cols = TRUE) d
library(tidyverse) library(ggpol) library(gganimate) g <- d %>% filter(Location == "World") %>% mutate(pop = ifelse(Sex == "Male", -Pop/1e3, Pop/1e3), sex = fct_rev(Sex), age = as.numeric(AgeGrp) - 1) %>% ggplot(mapping = aes(x = pop, y = age))+ geom_col(orientation = "y") + facet_share(facets = "sex", scales = "free_x") + scale_x_continuous(labels = abs) + theme_bw() + transition_time(time = Time) + labs(x = "Population (millions)", y = "", title = 'WPP2022 World Population Medium Variant {round(frame_time)}') animate(g, width = 15, height = 15, units = "cm", res = 200, renderer = gifski_renderer(), nframes = n_distinct(d$Time)) anim_save(filename = "wpp2022_med.gif")
knitr::include_graphics('https://raw.githubusercontent.com/guyabel/tidywpp/main/wpp2022_med.gif')
This package is in no way officially related to, or endorsed by, UN DESA.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.