-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.Rmd
95 lines (69 loc) · 2.54 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
output:
md_document:
variant: markdown_github
---
# WHO
[](http://cran.r-project.org/web/packages/WHO)
[](https://travis-ci.org/expersso/WHO)
[](https://codecov.io/github/expersso/WHO?branch=master)
[](http://cran.r-project.org/web/packages/WHO)
```{r options, echo=FALSE}
knitr::opts_chunk$set(cache = FALSE, warning = FALSE, error = FALSE,
fig.path = "")
library(WHO)
```
### Introduction
The `WHO` package allows the user to download public health data from the
[World Health Organization's](http://www.WHO.int/)
[Global Health Observatory](http://www.WHO.int/gho/en/)
in a dynamic and reproducible way.
The package can be installed from either CRAN or Github (development version):
```{r install, eval=FALSE}
# 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:
```{r get_codes}
library(dplyr)
codes <- get_codes()
head(codes)
```
(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:
```{r find_series}
codes[grepl("[Ll]ife expectancy", codes$display), ]
```
The `codes` data frame also provides a `url` to the meta data for a specified
series:
```{r, eval=FALSE}
# Opens a browser with the meta data for the specified series
browseURL(codes$url[1])
```
Having found the series of interest (in the `label` column), we can easily
retrieve the data and, for example, make a chart:
```{r example_1, fig.width=5, fig.height=3}
library(ggplot2)
df <- get_data("WHOSIS_000001")
head(df)
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.