forked from dgrtwo/data-screencasts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmalaria.Rmd
159 lines (130 loc) · 4.09 KB
/
malaria.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
---
title: "Malaria Atlas"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(tidyverse)
theme_set(theme_light())
library(malariaAtlas)
```
```{r}
kenya_pr <- tbl_df(malariaAtlas::getPR(ISO = "KEN", species = "BOTH")) %>%
filter(!is.na(pr))
```
```{r}
kenya_pr %>%
group_by(year_start) %>%
summarize(examined = sum(examined),
positive = sum(positive),
studies = n()) %>%
mutate(pr = positive / examined) %>%
ggplot(aes(year_start, pr)) +
geom_line()
kenya_pr %>%
mutate(decade = 10 * (year_start %/% 10)) %>%
arrange(pr) %>%
ggplot(aes(longitude, latitude, color = pr)) +
borders("world", regions = "Kenya") +
geom_point() +
scale_color_gradient2(low = "blue", high = "red", midpoint = .5, labels = scales::percent_format()) +
facet_wrap(~ decade) +
theme_void() +
coord_map() +
labs(color = "Prevalence")
```
### Aggregated across countries
```{r}
malaria_inc <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2018/2018-11-13/malaria_inc.csv")
malaria_inc_processed <- malaria_inc %>%
setNames(c("country", "code", "year", "incidence")) %>%
mutate(incidence = incidence / 1000)
```
```{r}
malaria_inc_processed %>%
filter(country %in% sample(unique(country), 6)) %>%
ggplot(aes(year, incidence, color = country)) +
geom_line() +
scale_y_continuous(labels = scales::percent_format())
```
Looking at 2015 levels and the change from 2015 to 2000
```{r}
malaria_spread <- malaria_inc_processed %>%
mutate(year = paste0("Y", year)) %>%
spread(year, incidence)
malaria_spread %>%
filter(country != "Turkey",
!is.na(code)) %>%
mutate(current = Y2015,
change = Y2015 - Y2000) %>%
ggplot(aes(current, change)) +
geom_point() +
geom_text(aes(label = code), vjust = 1, hjust = 1)
```
```{r}
world <- map_data("world") %>%
filter(region != "Antarctica")
malaria_inc_processed %>%
filter(incidence < 1) %>%
inner_join(maps::iso3166 %>%
select(a3, mapname), by = c(code = "a3")) %>%
inner_join(world, by = c(mapname = "region")) %>%
ggplot(aes(long, lat, group = group, fill = incidence)) +
geom_polygon() +
scale_fill_gradient2(low = "blue", high = "red", midpoint = .20, labels = scales::percent_format()) +
coord_map() +
facet_wrap(~ year) +
theme_void() +
labs(title = "Malaria incidence over time around the world")
```
### Malaria deaths over time
```{r}
library(tidyverse)
malaria_deaths <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2018/2018-11-13/malaria_deaths.csv")
malaria_deaths_processed <- malaria_deaths %>%
setNames(c("country", "code", "year", "deaths"))
```
```{r}
malaria_deaths_processed %>%
filter(country %in% sample(unique(country), 6)) %>%
ggplot(aes(year, deaths, color = country)) +
geom_line() +
labs(y = "Deaths per 100,000")
```
```{r}
library(fuzzyjoin)
library(stringr)
malaria_country_data <- malaria_deaths_processed %>%
inner_join(maps::iso3166 %>%
select(a3, mapname), by = c(code = "a3")) %>%
mutate(mapname = str_remove(mapname, "\\(.*"))
malaria_map_data <- map_data("world") %>%
filter(region != "Antarctica") %>%
tbl_df() %>%
inner_join(malaria_country_data, by = c(region = "mapname"))
malaria_map_data %>%
ggplot(aes(long, lat, group = group, fill = deaths)) +
geom_polygon() +
scale_fill_gradient2(low = "blue", high = "red", midpoint = 100) +
theme_void() +
labs(title = "Malaria deaths over time around the world",
fill = "Deaths per 100,000")
```
```{r}
library(gganimate)
library(countrycode)
library(gifski)
malaria_map_data %>%
mutate(continent = countrycode(code, "iso3c", "continent")) %>%
filter(continent == "Africa") %>%
ggplot(aes(long, lat, group = group, fill = deaths), renderer = gifski_renderer()) +
geom_polygon() +
scale_fill_gradient2(low = "blue", high = "red", midpoint = 100) +
theme_void() +
labs(title = "Malaria deaths over time in Africa ({ current_frame })",
fill = "Deaths per 100,000") +
transition_manual(year)
anim_save("malaria_map.gif")
```