library(sf)
library(ggrepel)
sf_moz <- cumulus::download_fieldmaps_sf(iso3 = "moz", layer = "moz_adm2")
# Last 3 days of exposure data
floodscan_last3 <- floodscan_adm2 |>
filter(valid_date >= max(valid_date) - 2)
# Join exposure to spatial (all provinces), filter out NA dates
sf_exposure <- sf_moz$moz_adm2 |>
left_join(floodscan_last3, by = c("ADM2_PCODE" = "pcode")) |>
filter(!is.na(valid_date))
# All province boundaries (light)
sf_provinces <- sf_moz$moz_adm2 |>
group_by(ADM1_PT) |>
summarise(geom = st_union(geom))
# Highlight boundaries for worst-affected provinces
sf_highlight <- sf_provinces |>
filter(ADM1_PT %in% c("Gaza", "Maputo", "Sofala"))
# Province label positions (centroids)
sf_prov_labels <- sf_highlight |>
mutate(
centroid = st_centroid(geom),
x = st_coordinates(centroid)[, 1],
y = st_coordinates(centroid)[, 2],
label = toupper(ADM1_PT)
)
# Top 3 worst districts per province (for labeling)
sf_top3 <- sf_exposure |>
filter(ADM1_PT %in% c("Gaza", "Maputo", "Sofala")) |>
group_by(valid_date, ADM1_PT) |>
slice_max(sum, n = 3) |>
ungroup() |>
mutate(centroid = st_centroid(geom)) |>
mutate(
x = st_coordinates(centroid)[, 1],
y = st_coordinates(centroid)[, 2]
)
ggplot() +
geom_sf(data = sf_exposure, aes(fill = sum), color = "white", linewidth = 0.3) +
geom_sf(data = sf_provinces, fill = NA, color = "grey70", linewidth = 0.5) +
geom_sf(data = sf_highlight, fill = NA, color = "#D62828", linewidth = 1.5) +
geom_text(
data = sf_prov_labels,
aes(x = x, y = y, label = label),
size = 5, color = "grey50", fontface = "bold", alpha = 0.7
) +
geom_label_repel(
data = sf_top3,
aes(x = x, y = y, label = ADM2_PT),
size = 4,
fill = alpha("white", 0.7),
label.size = 0.3,
fontface = "bold",
segment.color = "grey40",
segment.size = 0.4,
box.padding = 0.5,
point.padding = 0.3,
max.overlaps = 20,
min.segment.length = 0
) +
scale_fill_viridis_c(
option = "inferno",
direction = -1,
labels = scales::comma,
na.value = "grey90",
name = "Population Exposed"
) +
facet_wrap(~valid_date, ncol = 1) +
labs(
title = "FloodScan Exposure by District",
subtitle = "Gaza, Maputo, and Sofala highlighted | Top 3 districts labeled per province",
caption = "Data: FloodScan & WorldPop"
) +
theme_void(base_size = 14) +
theme(
strip.text = element_text(face = "bold", size = 18, margin = margin(b = 10)),
legend.position = "bottom",
legend.key.width = unit(4, "cm"),
legend.key.height = unit(0.6, "cm"),
legend.text = element_text(size = 12),
legend.title = element_text(size = 14, face = "bold"),
plot.title = element_text(face = "bold", size = 22),
plot.subtitle = element_text(color = "grey40", size = 14, margin = margin(b = 20))
)