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 CRAN status R-CMD-check

This package acts as an interface to Our World in Data datasets, allowing for an easy way to search through data used in over 3,000 charts and load them into the R environment.

After some updates to the Our World in Data site, some of the previous parts of the package are no longer working. Please install the development version of the pacakage to maintain core functionality of the owid() function. The site also now provides an API, this may offer an easier way to download datasets into R without a dependency on this package. For example using just data.table you can easily download a specific dataset. See more information on the API here: Our World in Data API

library(data.table)
life_expectancy <- fread("https://ourworldindata.org/grapher/life-expectancy.csv")

Installation

To install from CRAN:

install.packages("owidR")

To install the development version from GitHub:

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.

library(owidR)

owid_search("human rights") # this function is no longer working

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

rights <- owid("human-rights-index-vdem", rename = "vdem_rights")

rights

ggplot2 makes it easy to visualise our data.

library(ggplot2)
library(dplyr)

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

COVID-19 Data

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

covid <- owid_covid()

To-do



piersyork/owidR documentation built on April 17, 2025, 11:42 p.m.