
Plot rolling-mean year-on-year drivers of the change in territorial N losses
Source:R/decomposition_analysis.R
plot_loss_decomp_rolling.RdSame data as plot_loss_decomp_yearly(), but smooths each
year's own additive contribution with a centered rolling mean
(window years wide, NA-padded at the edges) before plotting, to
make sustained multi-year trends (e.g. a period of continuously
improving efficiency) easier to see than in the raw, noisy
year-on-year series.
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
# `window` must not exceed the number of years available per group.
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
)
)
plots <- plot_loss_decomp_rolling(decomp, window = 3)