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: 3 months ago
JSON representation
An R Package for Importing Data from Our World in Data
- Host: GitHub
- URL: https://github.com/piersyork/owidR
- Owner: piersyork
- License: other
- Created: 2021-06-28T18:06:02.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-06T09:57:25.000Z (6 months ago)
- Last Synced: 2025-07-07T00:03:45.649Z (3 months ago)
- Topics: data, data-visualisation, economics, r, r-package
- Language: R
- Homepage:
- Size: 2.71 MB
- Stars: 118
- Watchers: 4
- Forks: 11
- Open Issues: 5
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
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"))
)```
 [](https://CRAN.R-project.org/package=owidR)
[](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.
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](https://docs.owid.io/projects/etl/api/chart-api/#chart-data-api)
```{r}
library(data.table)
life_expectancy <- fread("https://ourworldindata.org/grapher/life-expectancy.csv")
```## 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") # this function is no longer working
```
Let's use the v-dem human rights index dataset.
```{r example2, eval = TRUE, message = FALSE}
rights <- owid("human-rights-index-vdem", rename = "vdem_rights")
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, vdem_rights, colour = entity)) +
geom_line()
```## COVID-19 Data
You can quickly download world covid-19 data, including vaccination rates, using `owid_covid()`.
```{r covid, eval=FALSE}
covid <- owid_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