-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_figures.R
288 lines (230 loc) · 11.8 KB
/
plot_figures.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
rm(list=ls())
# Load libraries
library(dplyr)
library(sf)
library(ggplot2)
library(ggpubr)
# Set global options
options(stringsAsFactors = FALSE)
# Load functions
source("R/recode_countries.R")
# Load data
fig_1a <- read.csv("output/figure_1a.csv")
fig_1b <- read.csv("output/figure_1b.csv")
fig_2a <- read.csv("output/figure_2a.csv")
fig_2b <- read.csv("output/figure_2b.csv")
fig_2c <- read.csv("output/figure_2c.csv")
fig_3a <- read.csv("output/figure_3a.csv")
fig_3b <- read.csv("output/figure_3b.csv")
fig_3c <- read.csv("output/figure_3c.csv")
fig_3d <- read.csv("output/figure_3d.csv")
fig_4a <- read.csv("output/figure_4a.csv")
fig_4b <- read.csv("output/figure_4b.csv")
fig_4c <- read.csv("output/figure_4c.csv")
# Load shapefile
world_shp <- read_sf("data/WHO Map boundaries/MapTemplate_detailed_2013/Shapefiles/detailed_2013.shp")
# Set colour palettes
map_col_pal <- c("Endemic"="#f44336", "In-progress"="#f28b30", "Free"="#03658c", "No answers received"="grey75")
col_pal <- c("Endemic"="#f44336", "In-progress"="#f28b30", "Free"="#03658c")
#----- Produce figure 1 --------------------------------------------------------
#----- Process data for map
# Fix geometry
world_shp_fixed <- st_make_valid(world_shp)
# Merge data into shapefile for plotting
world_shp_data <- merge(world_shp_fixed, fig_1a, by.x="CNTRY_TERR", by.y="country", all.y=T)
# Extract centroids for each country
country_centroids <- st_centroid(world_shp_fixed)
# Merge data into centroids and subset for interviewed countries
country_centroids <- country_centroids %>%
merge(., fig_1a, by.x="CNTRY_TERR", by.y="country", all.y=T) %>%
filter(interview == "Yes")
#----- Produce panel 1a
fig_1a_plot = ggplot() +
geom_sf(data=world_shp, fill="grey75", lwd=0.04, color="white") +
geom_sf(data=world_shp_data, aes(fill=endemic_status), color="white", lwd=0.04, alpha=0.8) +
scale_fill_manual(name="Dog-mediated rabies: ", values = map_col_pal, labels=c("Endemic ", "In-progress ", "Free ", "No answers received")) +
geom_sf(data=country_centroids, fill="black", shape=1, size=2.5, stroke=0.8) +
coord_sf() +
theme_void() +
theme(legend.position = "top", legend.title = element_text(size=10),
legend.text = element_text(size=10))
#----- Process data for barplot
# Set factors for bar order
fig_1b$work_sector <- factor(fig_1b$work_sector, levels=unique(fig_1b$work_sector))
# Set factors for colour order
fig_1b$endemic_status <- factor(fig_1b$endemic_status, levels=c("Endemic", "In-progress", "Free"))
#----- Produce panel 1b
fig_1b_plot = ggplot(data=fig_1b, aes(x=work_sector, y=n, fill=endemic_status)) +
geom_col(alpha=0.8) + # colour="white",
scale_fill_manual(name="Status of countries \nwith survey responses", values = map_col_pal, guide=guide_legend(order=1)) +
labs(x="Respondents'\naffiliation", y="Respondents") +
scale_x_discrete(limits=rev) +
scale_y_continuous(limits=c(0,30)) +
coord_flip() +
theme_classic() +
theme(legend.position = "none", axis.text = element_text(size=10))
# Combine plots and save output
ggarrange(fig_1a_plot, fig_1b_plot, ncol=1, heights=c(1.5,1), labels=c("A", "B"), common.legend = TRUE)
ggsave("figs/Figure_1.pdf", height=14, width=18, units = "cm")
#----- Produce figure 2 --------------------------------------------------------
#----- Process data for barplot
# Set factors for colour order
fig_2a$endemic_status <- factor(fig_2a$endemic_status, levels=c("Endemic", "In-progress", "Free"))
fig_2b$endemic_status <- factor(fig_2b$endemic_status, levels=c("Endemic", "In-progress", "Free"))
fig_2c$endemic_status <- factor(fig_2c$endemic_status, levels=c("Endemic", "In-progress", "Free"))
#----- Produce panel 2a
fig_2a_plot = ggplot(data=fig_2a, aes(x=result, y=n, fill=endemic_status)) +
geom_col(alpha=0.8)+
scale_fill_manual(name="Dog-mediated \nrabies: ",
values = col_pal, guide=guide_legend(order=1)) +
labs(title="Dog vaccination", x="", y="") +
scale_y_continuous(limits=c(0,40)) +
theme_classic() +
theme(axis.title.x = element_blank(), legend.title = element_text(size=6),
legend.title.align = 1, legend.text = element_text(size=6),
axis.title=element_text(size=7), title = element_text(size = 7),
axis.text = element_text(size=6))
#----- Produce panel 2b
fig_2b_plot = ggplot(data=fig_2b, aes(x=result, y=n, fill=endemic_status)) +
geom_col(alpha=0.8) +
scale_fill_manual(values = col_pal, guide=guide_legend(order=1)) +
labs(title="Post-exposure prophylaxis", x="", y="Respondents") +
scale_y_continuous(limits=c(0,40)) +
theme_classic() +
theme(axis.title.x = element_blank(), legend.title = element_text(size=6),
legend.text = element_text(size=6), axis.title=element_text(size=7),
title = element_text(size = 7), axis.text = element_text(size=6))
#----- Produce panel 2c
fig_2c_plot = ggplot(data=fig_2c, aes(x=result, y=n, fill=endemic_status)) +
geom_col(alpha=0.8) +
scale_fill_manual(values = col_pal, guide=guide_legend(order=1)) +
labs(title="Awareness activities", x="", y="") +
scale_y_continuous(limits=c(0,40)) +
theme_classic() +
theme(axis.title.x = element_blank(), legend.title = element_text(size=6),
legend.text = element_text(size=6), axis.title=element_text(size=7),
title = element_text(size = 7), axis.text = element_text(size=6))
#----- Combine and save
# Combine plots and save output
ggarrange(fig_2a_plot, fig_2b_plot, fig_2c_plot, ncol=1, common.legend = TRUE,
labels=c("A", "B", "C"))
ggsave("figs/Figure_2.pdf", height=16, width=8, units="cm")
#----- Produce figure 3 --------------------------------------------------------
#----- Process data for barplot
# Set factors for bar order
fig_3a$grouped_response <- factor(fig_3a$grouped_response, levels=unique(fig_3a$grouped_response))
fig_3b$grouped_response <- factor(fig_3b$grouped_response, levels=unique(fig_3b$grouped_response))
fig_3c$grouped_response <- factor(fig_3c$grouped_response, levels=unique(fig_3c$grouped_response))
fig_3d$grouped_response <- factor(fig_3d$grouped_response, levels=unique(fig_3d$grouped_response))
# Set factors for colour order
fig_3a$endemic_status <- factor(fig_3a$endemic_status, levels=c("Endemic", "In-progress", "Free"))
fig_3b$endemic_status <- factor(fig_3b$endemic_status, levels=c("Endemic", "In-progress", "Free"))
fig_3c$endemic_status <- factor(fig_3c$endemic_status, levels=c("Endemic", "In-progress", "Free"))
fig_3d$endemic_status <- factor(fig_3d$endemic_status, levels=c("Endemic", "In-progress", "Free"))
#----- Produce panel 3a
fig_3a_plot = ggplot(data=fig_3a, aes(x=grouped_response, y=n, fill=endemic_status)) +
geom_col(alpha=0.8, width=0.9)+
scale_fill_manual(name="Dog-mediated rabies: ", values = col_pal, guide=guide_legend(order=1)) +
labs(title="Dog vaccination", y="Countries\n") +
scale_y_continuous(limits=c(0,30)) +
theme_classic() +
scale_x_discrete(limits=rev) +
coord_flip() +
theme(axis.title.x = element_blank(), axis.title.y = element_blank(),
plot.title.position = "plot", plot.title = element_text(hjust=0.1, size = 10))
#----- Produce panel 3b
fig_3b_plot = ggplot(data=fig_3b, aes(x=grouped_response, y=n, fill=endemic_status)) +
geom_col(alpha=0.8)+
scale_fill_manual(values = col_pal, guide=guide_legend(order=1)) +
labs(title="Health seeking", y="Countries\n") +
scale_y_continuous(limits=c(0,30)) +
theme_classic() +
scale_x_discrete(limits=rev) +
coord_flip() +
theme(axis.title.x = element_blank(), axis.title.y = element_blank(),
plot.title.position = "plot", plot.title = element_text(hjust=0.1, size = 10))
#----- Produce panel 3c
fig_3c_plot = ggplot(data=fig_3c, aes(x=grouped_response, y=n, fill=endemic_status)) +
geom_col(alpha=0.8)+
scale_fill_manual(values = col_pal, guide=guide_legend(order=1)) +
labs(title="Post-exposure prophylaxis", y="Countries\n") +
scale_y_continuous(limits=c(0,30)) +
theme_classic() +
scale_x_discrete(limits=rev) +
coord_flip() +
theme(axis.title.y = element_blank(), axis.title.x = element_text(size=10),
plot.title.position = "plot", plot.title = element_text(hjust=0.15, size = 10))
#----- Produce panel 3d
fig_3d_plot = ggplot(data=fig_3d, aes(x=grouped_response, y=n, fill=endemic_status)) +
geom_col(alpha=0.8)+
scale_fill_manual(values = col_pal, guide=guide_legend(order=1)) +
labs(title="Surveillance", y="Countries\n") +
scale_y_continuous(limits=c(0,30)) +
theme_classic() +
scale_x_discrete(limits=rev) +
coord_flip() +
theme(axis.title.y = element_blank(), axis.title.x = element_text(size=10),
plot.title.position = "plot", plot.title = element_text(hjust=0.1, size = 10))
#----- Combine and save
# Combine plots and save output
ggarrange(fig_3a_plot, fig_3b_plot, fig_3c_plot, fig_3d_plot,
ncol=2, nrow=2, common.legend = TRUE,
labels=c("A", "B", "C", "D"), align="hv")
ggsave("figs/Figure_3.pdf", height=12, width=18, units = "cm")
#----- Figure 4 ----------------------------------------------------------------
#----- Process data for barplot
# Set factor for bar order
fig_4a$question <- factor(fig_4a$question, levels=unique(fig_4a$question))
fig_4b$question <- factor(fig_4b$question, levels=unique(fig_4b$question))
fig_4c$question <- factor(fig_4c$question, levels=unique(fig_4c$question))
# Set factors for colour order
fig_4a$endemic_status <- factor(fig_4a$endemic_status, levels=c("Endemic", "In-progress", "Free"))
fig_4b$endemic_status <- factor(fig_4b$endemic_status, levels=c("Endemic", "In-progress", "Free"))
fig_4c$endemic_status <- factor(fig_4c$endemic_status, levels=c("Endemic", "In-progress", "Free"))
#----- Produce panel 4a
fig_4a_plot = ggplot(data=fig_4a, aes(x=question, y=n, fill=endemic_status)) +
geom_col(alpha=0.8, width=0.9)+
scale_fill_manual(name="Dog-mediated \nrabies: ", values = col_pal, guide=guide_legend(order=1)) +
labs(title="Free-roaming dogs", y="") +
scale_y_continuous(limits=c(0,30)) +
theme_classic() +
scale_x_discrete(limits=rev) +
coord_flip() +
theme(axis.title.y = element_blank(),
legend.title = element_text(size=6), legend.title.align = 1,
legend.text = element_text(size=6), axis.title=element_text(size=7),
title = element_text(size = 7), axis.text = element_text(size=6),
plot.title.position = "plot", plot.title = element_text(hjust=0.1))
#----- Produce panel 4b
fig_4b_plot = ggplot(data=fig_4b, aes(x=question, y=n, fill=endemic_status)) +
geom_col(alpha=0.8, width=0.9)+
scale_fill_manual(values = col_pal, guide=guide_legend(order=1)) +
labs(title="Human-dog interactions", y="") +
scale_y_continuous(limits=c(0,30)) +
theme_classic() +
scale_x_discrete(limits=rev) +
coord_flip() +
theme(axis.title.y = element_blank(),
legend.title = element_text(size=6),
legend.text = element_text(size=6), axis.title=element_text(size=7),
title = element_text(size = 7), axis.text = element_text(size=6),
plot.title.position = "plot", plot.title = element_text(hjust=0.1))
#----- Produce panel 4c
fig_4c_plot = ggplot(data=fig_4c, aes(x=question, y=n, fill=endemic_status)) +
geom_col(alpha=0.8, width=0.9)+
scale_fill_manual(values = col_pal, guide=guide_legend(order=1)) +
labs(title="Media reporting of dogs", y="Countries\n") +
scale_y_continuous(limits=c(0,30)) +
theme_classic() +
scale_x_discrete(limits=rev) +
coord_flip() +
theme(axis.title.y = element_blank(),
legend.title = element_text(size=6),
legend.text = element_text(size=6), axis.title=element_text(size=7),
title = element_text(size = 7), axis.text = element_text(size=6),
plot.title.position = "plot", plot.title = element_text(hjust=0.1))
#----- Combine and save
# Combine plots and save output
ggarrange(fig_4a_plot, fig_4b_plot, fig_4c_plot, ncol=1, common.legend = TRUE,
labels=c("A", "B", "C"), align="v", heights=c(0.7,1,1))
ggsave("figs/Figure_4.pdf", height=12, width=8, units="cm")