An open API service indexing awesome lists of open source software.

https://github.com/guyabel/wcde

Package to download data from the Wittgenstein Centre Human Capital Data Explorer into R
https://github.com/guyabel/wcde

demography demograpic-data population-data r rstats rstats-package

Last synced: about 1 year ago
JSON representation

Package to download data from the Wittgenstein Centre Human Capital Data Explorer into R

Awesome Lists containing this project

README

          

---
output: github_document
---

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

# wcde

[![CRAN status](https://www.r-pkg.org/badges/version/wcde)](https://CRAN.R-project.org/package=wcde)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/grand-total/wcde?color=blue)](https://r-pkg.org/pkg/wcde)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![R-CMD-check](https://github.com/guyabel/wcde/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/guyabel/wcde/actions/workflows/R-CMD-check.yaml)

Download data from the [Wittgenstein Centre for Demography and Human Capital Data Explorer](http://dataexplorer.wittgensteincentre.org/) into R

See the [pkgdown site](https://guyabel.github.io/wcde/) for full details.

## Installation

You can install the released version of `wcde` from [CRAN](https://CRAN.R-project.org) with:

```{r eval=FALSE}
install.packages("wcde")
```

Install the developmental version with:

```{r eval=FALSE}
library(devtools)
install_github("guyabel/wcde", ref = "main")
```

## Example

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

```{r example}
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](https://guyabel.github.io/wcde/articles/wcde.html) provides many more examples on how to use the package to download data and produce plots from the Wittgenstein Centre Human Capital Data Explorer.

```{r, echo=FALSE, eval=FALSE}
# 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")
```

```{r echo=FALSE, out.height="600px", out.width="600px"}
knitr::include_graphics('https://raw.githubusercontent.com/guyabel/wcde/main/world6_ssp2.gif')
```