/
24_Statistics.Rmd
132 lines (116 loc) · 4.13 KB
/
24_Statistics.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
---
title: "#30DayMapChallenge Day 24: Statistics - Variance in Malaria Deaths"
author: "Cedric Scherer"
date: "24th of November 2019"
output:
html_document:
theme: paper
highlight: kate
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = F)
```
```{r prep, message=FALSE, warning=FALSE}
library(tidyverse)
library(sf)
library(biscale)
library(cowplot)
library(extrafont)
extrafont::loadfonts()
theme_set(theme_minimal())
theme_update(
axis.ticks = element_blank(),
axis.text = element_blank(),
panel.grid.major = element_blank(),
panel.background = element_rect(color = NA,
fill = "white"),
plot.background = element_rect(color = "#806A8A",
fill = "white",
size = 5),
plot.title = element_text(family = "Changa One",
color = "black",
size = 44,
face = "bold",
hjust = 0.5,
margin = margin(t = 36, b = 6)),
plot.subtitle = element_text(family = "Changa One",
color = "#CABED0",
size = 21,
hjust = 0.5,
margin = margin(t = 6, b = 20)),
plot.caption = element_text(family = "Changa One",
color = "#806A8A",
size = 21,
face = "plain",
hjust = 0.5,
margin = margin(t = 0, b = 36))
)
```
```{r data-prep}
df_malaria <-
readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2018/2018-11-13/malaria_deaths.csv") %>%
rename(malaria_deaths = "Deaths - Malaria - Sex: Both - Age: Age-standardized (Rate) (per 100,000 people)")
sf_world <-
st_as_sf(rworldmap::getMap(resolution = "low")) %>%
st_transform(crs = "+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs") %>%
dplyr::select(ISO_A3, continent)
sf_malaria <-
sf_world %>%
full_join(df_malaria, by = c("ISO_A3" = "Code"))
```
```{r map, fig.width = 18, fig.height = 11.9}
sf_malaria_bi <-
sf_malaria %>%
filter(
continent == "Africa",
!is.na(Year)
) %>%
group_by(ISO_A3) %>%
summarize(
var = var(malaria_deaths, na.rm = T),
mean = mean(malaria_deaths, na.rm = T)
) %>%
bi_class(x = mean, y = var, style = "quantile", dim = 3)
bi_map <-
ggplot(sf_malaria_bi) +
geom_sf(data = sf_world %>% filter(continent == "Africa"),
color = "grey20",
fill = "grey70",
lwd = 0.2) +
geom_sf(aes(fill = bi_class),
color = "grey20",
lwd = 0.2) +
bi_scale_fill(pal = "DkViolet", dim = 3, guide = F) +
scale_x_continuous(expand = c(0.03, 0.03)) +
scale_y_continuous(expand = c(0.03, 0.03), limits = c(-4200000, NA)) +
labs(x = NULL, y = NULL,
title = "Malaria Death Rates between 1990 and 2016",
subtitle = "A bivariate map showing mean and variance of annual Malaria death rates in African countries",
caption = "Visualization by Cédric Scherer • Data by World Health Organization (WHO) ")
legend <-
bi_legend(pal = "DkViolet",
dim = 3,
xlab = "Mean ",
ylab = "Variance ") +
bi_theme(base_family = "Changa One") +
theme(rect = element_rect(fill = "grey10"),
panel.border = element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank(),
axis.title.x = element_text(size = 21,
color = "#BC7C8F"),
axis.title.y = element_text(size = 21,
color = "#89A1C8"))
map_legend <-
ggdraw() +
draw_plot(bi_map, 0, 0, 1, 1) +
draw_plot(legend, 0.15, 0.25, 0.2, 0.2)
ggsave(here::here("contributions", "Day24_Statistics", "Statistics_MalariaDeaths.pdf"),
plot = map_legend, width = 15, height = 16.5, device = cairo_pdf)
```
***
```{r session-info}
sessionInfo()
```