# Color palette matching monitoring plot style
pal_components <- c(
"CDI" = "black",
"VHI" = "#CCEBC5",
"MAM precip (mixed obs forecast)" = "#DECBE4",
"Snow Cover" = "#FFFF90",
"ASI" = "#FBB4AE",
"Soil moisture" = "#fec44f"
)
# Map component names to nice labels
component_label_map <- c(
"vhi" = "VHI",
"mixed_fcast_obsv" = "MAM precip (mixed obs forecast)",
"snow_cover" = "Snow Cover",
"asi" = "ASI",
"volumetric_soil_water_1m" = "Soil moisture"
)
df_components <- df_apr_cdi |>
select(year, drought, all_of(cdi_weights$term), CDI) |>
pivot_longer(cols = all_of(cdi_weights$term),
names_to = "component", values_to = "zscore") |>
mutate(
parameter_label = component_label_map[component],
parameter_label = factor(parameter_label, levels = names(pal_components))
)
# CDI data for separate layer
df_cdi_line <- df_apr_cdi |>
mutate(parameter_label = "CDI")
# Drought years for points and labels
df_drought_years <- df_apr_cdi |>
filter(drought == "yes")
p_cdi_components <- ggplot() +
# Component lines with shadow
ggfx::with_shadow(
geom_line(
data = df_components,
aes(x = year, y = zscore, color = parameter_label, group = parameter_label),
alpha = 1, linewidth = 0.5
),
sigma = 1.0, x_offset = 0.5, y_offset = 0.25
) +
# Threshold line
geom_hline(
yintercept = cdi_threshold,
color = hdx_hex("tomato-dark"),
linetype = "dashed", linewidth = 0.5
) +
# CDI line with shadow (on top)
ggfx::with_shadow(
geom_line(
data = df_cdi_line,
aes(x = year, y = CDI),
color = "black", linewidth = 1
),
sigma = 2, x_offset = 0.5, y_offset = 0.25
) +
# Drought year points
geom_point(
data = df_drought_years,
aes(x = year, y = CDI),
color = hdx_hex("tomato-hdx"),
size = 2.5, alpha = 0.7
) +
# Threshold label
geom_label(
aes(x = 1990, y = cdi_threshold,
label = paste0("Threshold: ", round(cdi_threshold, 2))),
vjust = -0.3, hjust = 0,
color = hdx_hex("tomato-dark"),
size = 4, alpha = 0.5,
label.padding = unit(0.15, "cm")
) +
# Year labels for drought years
geom_text_repel(
data = df_drought_years,
aes(x = year, y = CDI, label = year),
color = hdx_hex("tomato-hdx"),
vjust = -2, size = 3.5, alpha = 1
) +
# Scales
scale_color_manual(values = pal_components, drop = FALSE, name = NULL) +
scale_x_continuous(
breaks = seq(1985, 2025, by = 5),
expand = expansion(mult = c(0.01, 0.03))
) +
# Labels
labs(
title = "Drought AA Afghanistan: 2026 April Trigger",
subtitle = "Red dashed line represents RP 4 threshold",
x = NULL,
y = "Indicator anomaly"
) +
theme(
axis.title.x = element_blank(),
axis.title.y = element_text(size = 14),
title = element_text(size = 16),
legend.key.width = unit(1, "cm"),
plot.subtitle = element_text(size = 14, color = "grey40"),
legend.title = element_blank(),
legend.text = element_text(size = 12),
legend.position = "bottom",
axis.text.y = element_text(angle = 90, size = 10, hjust = 0.5),
axis.text.x = element_text(size = 10),
panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank()
) +
guides(color = guide_legend(nrow = 1, override.aes = list(linewidth = 2)))
ggsave("outputs/figures/fig-cdi-components.png", p_cdi_components, width = 10, height = 6, dpi = 300)
# Paper version with larger text
p_cdi_components_paper <- p_cdi_components +
theme(
axis.title.y = element_text(size = 16),
title = element_text(size = 18),
plot.subtitle = element_text(size = 16, color = "grey40"),
legend.text = element_text(size = 14),
axis.text.y = element_text(angle = 90, size = 12, hjust = 0.5),
axis.text.x = element_text(size = 12)
)
ggsave("outputs/figures/paper/fig-cdi-components.png", p_cdi_components_paper, width = 10, height = 6, dpi = 300)
p_cdi_components