-
Notifications
You must be signed in to change notification settings - Fork 15
/
prep readme maps.R
162 lines (154 loc) · 5.76 KB
/
prep readme maps.R
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
159
160
161
162
library(tidyverse)
library(sf)
library(viridis)
library(patchwork)
shp_la <- read_sf("output/vulnerability-la.geojson") %>%
select(lad19cd = Code,
Vulnerability_q = Vulnerability.quintile,
geometry)
shp_msoa <- read_sf("output/vulnerability-MSOA-UK.geojson") %>%
select(Code,
decile = Vulnerability.decile,
geometry)
theme_map <- function(...) {
theme_minimal() +
theme(
text = element_text(family = "FiraCode-Retina", color = "#22211d"),
axis.line = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major = element_line(color = "#ebebe5", size = 0.2),
panel.grid.minor = element_blank(),
plot.background = element_rect(fill = "#f5f5f2", color = NA),
panel.background = element_rect(fill = "#f5f5f2", color = NA),
legend.background = element_rect(fill = "#f5f5f2", color = NA),
panel.border = element_blank(),
legend.title = element_text(size = 11),
legend.text = element_text(size = 9, hjust = 0),
plot.title = element_text(size = 15, hjust = 0.5,
margin = margin(b = 0.2,
t = 0.5,
l = 2,
unit = "cm")),
plot.subtitle = element_text(size = 10, hjust = 0.5,
margin = margin(b = 0.2,
t = 0.2,
l = 2,
unit = "cm"),
debug = F),
plot.caption = element_text(size = 7,
hjust = .5,
margin = margin(t = 0.2,
b = 0.5,
unit = "cm"),
color = "#939184"),
...
)
}
# White theme
theme_map <- function(...) {
theme_minimal() +
theme(
text = element_text(family = "FiraCode-Retina", color = "#22211d"),
axis.line = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
# panel.grid.minor = element_line(color = "#ebebe5", size = 0.2),
panel.grid.major = element_line(color = "#ebebe5", size = 0.2),
panel.grid.minor = element_blank(),
plot.background = element_rect(fill = "#ffffff", color = NA),
panel.background = element_rect(fill = "#ffffff", color = NA),
legend.background = element_rect(fill = "#ffffff", color = NA),
panel.border = element_blank(),
# Add labs elements
legend.title = element_text(size = 11),
legend.text = element_text(size = 9, hjust = 0),
plot.title = element_text(size = 15, hjust = 0.5),
plot.subtitle = element_text(
size = 10, hjust = 0.5,
margin = margin(
b = 0.2,
t = 0.2,
l = 2,
unit = "cm"
),
debug = F
),
# captions
plot.caption = element_text(
size = 7,
hjust = .5,
margin = margin(
t = 0.2,
b = 0,
unit = "cm"
),
color = "#939184"
),
...
)
}
plot_la <- ggplot(shp_la) +
geom_sf(mapping = aes(fill = Vulnerability_q),
color = "black",
size = 0.1) +
scale_fill_viridis(
breaks = seq(1, 5, by = 1),
labels = seq(1, 5, by = 1),
na.value = "transparent",
option = "magma",
name = expression(paste("Vulnerability \nQuintile")),
alpha = 0.8, # make fill a bit brighter
begin = 0.1, # this option seems to be new (compared to 2016):
# with this we can truncate the
# color scale, so that extreme colors (very dark and very bright) are not
# used, which makes the map a bit more aesthetic
end = 0.9,
discrete = F, # discrete classes, thus guide_legend instead of _colorbar
direction = -1, # dark is lowest, yellow is highest
guide = guide_legend(
keyheight = unit(5, units = "mm"),
title.position = "top",
reverse = T)) +
theme_map() +
theme(plot.margin = unit(c(0.5, 1.5, 0.5, 1.5), "cm"))
plot_msoa <- ggplot(shp_msoa) +
geom_sf(mapping = aes(fill = decile),
color = "black",
size = 0.05) +
scale_fill_viridis(
breaks = seq(1, 10, by = 1),
labels = seq(1, 10, by = 1),
na.value = "transparent",
option = "magma",
name = expression(paste("Vulnerability \nDecile")),
alpha = 0.8, # make fill a bit brighter
begin = 0.1, # this option seems to be new (compared to 2016):
# with this we can truncate the
# color scale, so that extreme colors (very dark and very bright) are not
# used, which makes the map a bit more aesthetic
end = 0.9,
discrete = F, # discrete classes, thus guide_legend instead of _colorbar
direction = -1, # dark is lowest, yellow is highest
guide = guide_legend(
keyheight = unit(5, units = "mm"),
title.position = "top",
reverse = T)) +
theme_map() +
theme(plot.margin = unit(c(0.5, 1.5, 0.5, 1.5), "cm"))
plot_la + plot_msoa + plot_annotation(
tag_levels = 'a',
title = "LA (a) and MSOA (b) vulnerability index scores",
subtitle = "Coloured by vulnerability quintiles (a) and deciles (b)",
caption = "Code: https://github.com/britishredcrosssociety/covid-19-vulnerability/",
theme = theme_map()
)
ggsave(filename = "maps/uk-vi-la-msoa.png",
width = 18,
height = 14)