Mapping Simulations
Adam H. Sparks
mapping.Rmd
You may wish to compare the effects of different establishment dates, different seasons or different locations on disease levels. This vignette details how you can automate several runs of {epicrop} in R and visualise them on maps. If you have not familiarised yourself with the workflow for multiple runs in the “Multiple Simulations” vignette, please read that first if you are unfamiliar with using {purrr}.
Map of AUDPC at multiple locations
In this example we will fetch data for the Mekong River Delta and Red River Delta in Vietnam; Prachin Buri, Thailand; Chennai, India and Nueva Ecija, in the Philippines for the wet season (second half of the year) in 2000. The map will show a point, with the size relative to the AUDPC value for that location using the latitude and longitude values that were supplied to fetch the weather data.
The {ggspatial} package is used to provide a base layer of countries using Open Street Map map baselayer data and labelling capabilities.
library("epicrop")
library("purrr")
library("dplyr")
library("ggplot2")
library("ggspatial")
locations <- list(
"Mekong River" = c(105.5943, 10.0634),
"Red River" = c(105.9700, 20.9034),
"Prachin Buri" = c(101.6601, 14.0421),
"Chennai" = c(80.2707, 13.0827),
"Neuva Ecija" = c(121.1113, 15.5784)
)
locations_wth <-
map(
.x = locations,
.f = get_wth,
dates = "2000-06-30",
duration = 120
)
# `map()` from purrr is not to be confused with the actual map we are creating
map(
.x = locations_wth,
.f = ~ predict_bacterial_blight(emergence = .x$YYYYMMDD[1],
wth = .x)
) |>
bind_rows(.id = "location") |>
group_by(location) |>
distinct(AUDPC, location, lon, lat) |>
ggplot(aes(x = lon, y = lat)) +
annotation_map_tile(type = "cartolight",
zoomin = 0) +
geom_spatial_point(aes(size = AUDPC)) +
geom_spatial_label_repel(aes(label = paste(location,
round(AUDPC, 0),
sep = ", ")),
box.padding = 1,
size = 3) +
theme(
legend.position = c(.025, .025),
legend.justification = c("left", "bottom"),
legend.box.just = "right",
legend.margin = margin(3, 3, 3, 3),
legend.direction = "horizontal",
legend.spacing.y = unit(0, "mm"),
panel.border = element_rect(colour = "black", fill = NA),
axis.text = element_text(colour = 1, size = 12),
legend.background = element_blank(),
legend.key = element_blank(),
legend.box.background = element_rect(colour = "black")
) +
labs(
x = "Longitude",
y = "Latitude"
) +
ylim(c(0, 25)) +
xlim(c(75, 127)) +
coord_sf(crs = 4326)
#>
|
| | 0%
|
|=== | 4%
|
|======= | 8%
|
|========== | 12%
|
|============== | 17%
|
|================= | 21%
|
|===================== | 25%
|
|======================== | 29%
|
|============================ | 33%
|
|=============================== | 38%
|
|=================================== | 42%
|
|====================================== | 46%
|
|========================================== | 50%
|
|============================================= | 54%
|
|================================================ | 58%
|
|==================================================== | 62%
|
|======================================================= | 67%
|
|=========================================================== | 71%
|
|============================================================== | 75%
|
|================================================================== | 79%
|
|===================================================================== | 83%
|
|========================================================================= | 88%
|
|============================================================================ | 92%
|
|================================================================================ | 96%
|
|===================================================================================| 100%