Programmatic Data Retrieval from the WHO

Eric Persson

2019-10-28

Introduction

The WHO package allows the user to download public health data from the World Health Organization’s Global Health Observatory in a dynamic and reproducible way.

The package can be installed from either CRAN or Github (development version):

# From CRAN
install.packages("WHO")

# From Github
library(devtools)
install_github("expersso/WHO")

library(WHO)

Usage Example

The get_codes function returns a data frame with series codes and descriptions for all available series:

library(dplyr)

codes <- get_codes()
glimpse(codes)
## Observations: 3,287
## Variables: 3
## $ label   <chr> "MDG_0000000001", "MDG_0000000003", "MDG_0000000005", ...
## $ display <chr> "Infant mortality rate (probability of dying between b...
## $ url     <chr> "https://www.who.int/uat-portal/indicator-metadata-reg...

(To retrieve additional meta information (e.g. French and Spanish descriptions, category breakdowns of series, etc), use get_codes(extra = TRUE).)

To find a series of interest, use either View(codes) in Rstudio, or search with regular expressions:

codes[grepl("[Ll]ife expectancy", codes$display), ]
## # A tibble: 4 x 3
##   label     display                    url                                 
##   <chr>     <chr>                      <chr>                               
## 1 WHOSIS_0~ Life expectancy at birth ~ https://www.who.int/uat-portal/indi~
## 2 WHOSIS_0~ Healthy life expectancy (~ https://www.who.int/uat-portal/indi~
## 3 WHOSIS_0~ Life expectancy at age 60~ https://www.who.int/uat-portal/indi~
## 4 WHOSIS_0~ Healthy life expectancy (~ https://www.who.int/uat-portal/indi~

Having found the series of interest (in the label column), we can easily retrieve the data and, for example, make a chart:

library(ggplot2)

df <- get_data("WHOSIS_000001")

head(df)
## # A tibble: 6 x 7
##    year gho                      country sex      region publishstate value
##   <dbl> <chr>                    <chr>   <chr>    <chr>  <chr>        <dbl>
## 1  2001 Life expectancy at birt~ Rwanda  Both se~ Africa Published     46.5
## 2  2002 Life expectancy at birt~ Rwanda  Male     Africa Published     46  
## 3  2004 Life expectancy at birt~ Rwanda  Female   Africa Published     54.6
## 4  2004 Life expectancy at birt~ Rwanda  Both se~ Africa Published     51.9
## 5  2005 Life expectancy at birt~ Rwanda  Male     Africa Published     51  
## 6  2007 Life expectancy at birt~ Rwanda  Female   Africa Published     62.2
df %>% 
  filter(sex == "Both sexes") %>% 
  group_by(region, year) %>%
  summarise(value = mean(value)) %>% 
  ggplot(aes(x = year, y = value, color = region, linetype = region)) +
  geom_line(size = 1) +
  theme_light(9) +
  labs(x = NULL, y = "Life expectancy at birth (years)\n", 
       linetype = NULL, color = NULL,
       title = "Evolution of life expectancy (by region)\n")

Disclaimer

This package is in no way officially related to or endorsed by the WHO.