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)
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: 2,144
## Variables: 3
## $ label (chr) "MDG_0000000001", "MDG_0000000003", "MDG_0000000005", ...
## $ display (chr) "Infant mortality rate (probability of dying between b...
## $ url (chr) "http://apps.who.int/gho/indicatorregistry/App_Main/vi...
(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), ]
## Source: local data frame [3 x 3]
##
## label display
## (chr) (chr)
## 1 WHOSIS_000001 Life expectancy at birth (years)
## 2 WHOSIS_000002 Healthy life expectancy (HALE) at birth (years)
## 3 WHOSIS_000015 Life expectancy at age 60 (years)
## Variables not shown: url (chr)
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)
## Source: local data frame [6 x 8]
##
## publishstate year sex gho
## (chr) (dbl) (chr) (chr)
## 1 Published 1990 Both sexes Life expectancy at birth (years)
## 2 Published 2000 Both sexes Life expectancy at birth (years)
## 3 Published 2012 Female Life expectancy at birth (years)
## 4 Published 2000 Male Life expectancy at birth (years)
## 5 Published 2012 Male Life expectancy at birth (years)
## 6 Published 2000 Both sexes Life expectancy at birth (years)
## Variables not shown: region (chr), country (chr), worldbankincomegroup
## (chr), value (dbl)
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")
This package is in no way officially related to or endorsed by the WHO.