
Plot rolling-mean year-on-year drivers of territorial N losses, as one combined panel plot
Source:R/decomposition_analysis.R
plot_loss_decomp_rolling_panel.RdCombines the two views from plot_loss_decomp_rolling()
(by compartment and by mechanism) side by side into a single
patchwork plot, matching plot_loss_decomp_periods_panel()'s
style: one shared y-axis label, each panel keeping its own legend
(compartment and mechanism are different fill scales, so the legends
aren't collected into one).
Arguments
- decomp
A named list from
decompose_terr_losses(). IfNULL, computed automatically (slow).- window
Width of the centered rolling-mean window, in years. Default
10.
Examples
if (
requireNamespace("ggplot2", quietly = TRUE) &&
requireNamespace("patchwork", quietly = TRUE)
) {
decomp <- list(
by_compartment = tibble::tribble(
~t0, ~compartment, ~contribution_mgn, ~cumulative_mgn,
1861, "cropland", 12000, 12000,
1862, "cropland", 8000, 20000,
1863, "cropland", 9000, 29000
),
by_mechanism = tibble::tribble(
~t0, ~mechanism, ~contribution_mgn, ~cumulative_mgn,
1861, "Size", 9000, 9000,
1862, "Size", 5000, 14000,
1863, "Size", 6000, 20000
)
)
panel <- plot_loss_decomp_rolling_panel(decomp, window = 3)
}