Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/piersyork/owidR

An R Package for Importing Data from Our World in Data
https://github.com/piersyork/owidR

data data-visualisation economics r r-package

Last synced: about 1 month ago
JSON representation

An R Package for Importing Data from Our World in Data

Awesome Lists containing this project

README

        

---
title: "owidR"
output: github_document
always_allow_html: true
---

```{r, echo = FALSE, message=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "##",
fig.path = "inst/images/", fig.width=8.5, fig.asp=0.55, fig.align='center',
message = FALSE
)

library(ggplot2)

ggplot2::theme_set(
theme_minimal(base_family = "serif") %+replace%
theme(text = element_text(colour = "#373737", size = 18),
plot.title = element_text(size = "22", hjust = 0, vjust = 3.2, face = "bold"),
plot.subtitle = element_text(hjust = 0, vjust = 3.5),
plot.title.position = "plot",
plot.caption.position = "plot",
plot.caption = element_text(hjust = 0, size = 14, vjust = -1),
legend.position = "right",
axis.text = element_text(face = "plain"),
axis.title.x = element_blank(),
legend.title = element_blank(),
panel.grid.major = element_line(linetype = "dashed"),
panel.grid.minor = element_blank(),
plot.margin = margin(11, 15, 8, 0),
axis.line.x = element_line(colour = "#8e8e8e"),
axis.ticks = element_line(colour = "#8e8e8e"))
)

```

![CRAN downloads](http://cranlogs.r-pkg.org/badges/grand-total/owidR) [![CRAN status](https://www.r-pkg.org/badges/version/owidR)](https://CRAN.R-project.org/package=owidR)
[![R-CMD-check](https://github.com/piersyork/owidR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/piersyork/owidR/actions/workflows/R-CMD-check.yaml)

This package acts as an interface to [Our World in Data](https://ourworldindata.org/) datasets, allowing for an easy way to search through data used in over 3,000 charts and load them into the R environment.

## Installation

To install from CRAN:

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

To install the development version from GitHub:

```{r eval = FALSE}
devtools::install_github("piersyork/owidR")
```

## Using the package

The main function in owidR is `owid()`, which takes a chart id and returns a data.table of the corresponding OWID dataset. To search for chart ids you can use `owid_search()` to list all the chart ids that match a keyword or regular expression.

## Example

Lets use the core functions to get data on how human rights have changed over time. First by searching for charts on human rights.

```{r example, eval = TRUE, message = FALSE}
library(owidR)

owid_search("human rights")

```

Let's use the v-dem human rights index dataset.

```{r example2, eval = TRUE, message = FALSE}

rights <- owid("human-rights-index-vdem")

rights

```

ggplot2 makes it easy to visualise our data.

```{r plot}
library(ggplot2)
library(dplyr)

rights |>
filter(entity %in% c("United Kingdom", "France", "United States")) |>
ggplot(aes(year, civ_libs_vdem_owid, colour = entity)) +
geom_line()
```

## COVID-19 Data

You can quickly download world covid-19 data, including vaccination rates, using `owid_covid()`.

```{r covid}
covid <- owid_covid()

str(covid)
```

## To-do

- [ ] Add function to load multiple country datasets into one dataframe
- [ ] Add caching of data (inc. backend)
- [x] Remove interactive plotting to reduce dependencies
- [ ] Create way to import owid explorers