knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

wcde

CRAN status CRAN RStudio mirror downloads Lifecycle: experimental R-CMD-check

Download data from the Wittgenstein Centre for Demography and Human Capital Data Explorer into R

See the pkgdown site for full details.

Installation

You can install the released version of wcde from CRAN with:

install.packages("wcde")

Install the developmental version with:

library(devtools)
install_github("guyabel/wcde", ref = "main")

Example

Download data based on a indicator, scenario and country code:

library(wcde)

# SSP2 education specific tfr for Austria
get_wcde(indicator = "etfr", country_name = "Austria")

# SSP2 education specific population sizes for Iran and Kenya
get_wcde(indicator = "pop", country_code = c(364, 404), pop_edu = "four")

# SSP1, 2 and 3 gender gaps in educational attainment (15+) for all countries
get_wcde(indicator = "ggapedu15", scenario = 1:3)

Vignette

The vignette provides many more examples on how to use the package to download data and produce plots from the Wittgenstein Centre Human Capital Data Explorer.

# run by hand
library(gganimate)

d <- get_wcde(indicator = "epop", country_code = 900) 

g <- d %>%
  edu_group_sum(n = 6) %>%
  mutate(pop = ifelse(test = sex == "Male", yes = -epop, no = epop),
         pop = pop/1e3,
         pop_max = ifelse(sex == "Male", -max(pop), max(pop))) %>%
  ggplot(mapping = aes(x = pop, y = age, fill = fct_rev(education))) +
  geom_col() +
  geom_vline(xintercept = 0, colour = "black") +
  scale_x_continuous(labels = abs, expand = c(0, 0)) +
  scale_fill_manual(values = wic_col6, name = "Education") +
  facet_wrap(facets = "sex", scales = "free_x", strip.position = "bottom") +
  geom_blank(mapping = aes(x = pop_max * 1.1)) +
  theme(panel.spacing.x = unit(0, "pt"),
        strip.placement = "outside",
        strip.background = element_rect(fill = "transparent"),
        strip.text.x = element_text(margin = margin( b = 0, t = 0))) +
  transition_time(time = year) +
  labs(x = "Population (millions)", y = "Age", 
       title = 'SSP2 World Population {round(frame_time)}')

animate(g, width = 15, height = 15, units = "cm", res = 200, 
        renderer = gifski_renderer())

anim_save(filename = "world6_ssp2.gif")
knitr::include_graphics('https://raw.githubusercontent.com/guyabel/wcde/main/world6_ssp2.gif')


guyabel/wcde documentation built on April 17, 2025, 1:49 p.m.