This code will load the required packages needed to explore the WHO() function. 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.:
library(dplyr)
##
## Attaching package: 'dplyr'
##
## The following objects are masked from 'package:stats':
##
## filter, lag
##
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(devtools)
library(WHO)
This code will return a data frame with series codes and descriptions for all available series:
codes <- get_codes()
head(codes)
## Source: local data frame [6 x 3]
##
## label
## (chr)
## 1 MDG_0000000001
## 2 MDG_0000000003
## 3 MDG_0000000005
## 4 MDG_0000000006
## 5 MDG_0000000007
## 6 MDG_0000000010
## Variables not shown: display (chr), url (chr)
This code can be used to find a series of interest (dplyr opens the data in a seperate window):
View(codes)
Having found a series of interest in the label column, this code retrieves the data and, for example, makes a chart:
library(ggplot2)
df <- get_data("WHOSIS_000001")
head(df)
## Source: local data frame [6 x 8]
##
## worldbankincomegroup gho sex
## (chr) (chr) (chr)
## 1 High-income Life expectancy at birth (years) Male
## 2 High-income Life expectancy at birth (years) Both sexes
## 3 High-income Life expectancy at birth (years) Male
## 4 High-income Life expectancy at birth (years) Both sexes
## 5 High-income Life expectancy at birth (years) Female
## 6 High-income Life expectancy at birth (years) Both sexes
## Variables not shown: country (chr), year (dbl), region (chr), publishstate
## (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")