Joins trend statistics with variable metadata and computes Total
Change (slope x years). Returns a tibble ready for
DT::datatable() or gt::gt().
Arguments
- trend
A tibble from
cd_trend().- region_name
Optional character label for the AOI. If provided, adds a
Regioncolumn.
Value
A tibble with columns Parameter, Period, Slope, Years,
Total Change, Unit, p-value, and optionally Region. When trend
mixes raw-value and anomaly trends, a Trend on column follows Period.
When it holds more than one trend_start, a Start column follows
Period (or Trend on).
Details
Labels and units come from long_name and unit columns on trend
where present and not NA (carried by cd_trend() from the input
contract in cd_anomaly()), otherwise from cd_variables() — by
the same rules as cd_anomaly(), so a registered variable trended
under a different anomaly_type gets no registry unit. A variable
found in neither is labelled by its name, with no unit. On a trend of
raw values (trend_on == "value") Unit is shown only for absolute
and pct_point_diff series — the anomaly unit of a pct_normal
series is "%", which does not describe a slope in mm — so it agrees
with the axis label of cd_plot_timeseries() on the same series.
Rows are kept distinguishable. A long_name shared by several variables
(one label on many stations) gets the variable name appended, as in
cd_plot_comparison(): "Mean discharge (q_site1)". A table holding both
raw-value and anomaly trends, such as
dplyr::bind_rows(cd_trend(x), cd_trend(ano)), gains a Trend on column
("Value" or "Anomaly"; a missing or NA trend_on reads as
"Anomaly"). A table on one scale has no such column. Likewise a table
holding several trend windows, such as
cd_trend(x, trend_start = c(1951, 1981)), gains a Start column: the
start year asked of cd_trend(), not the first year with data. It is
added when the table as a whole holds more than one trend_start (an NA
counts as one), so binding a 1991 trend of one station to a 2000 trend of
another adds it too; a table with one window, or no trend_start column,
has none. All three are decided within one call, so summaries
bound together (one per region, each with its region_name) can differ in
suffixes, and a Trend on or Start column present in only some of them
is NA for the rest.
Examples
catalog <- cd_catalog(
system.file("extdata", "example_catalog.json", package = "cd")
)
aoi <- sf::st_read(
system.file("extdata", "example_aoi.gpkg", package = "cd"),
quiet = TRUE
)
ts <- cd_extract(catalog, aoi)
trn <- cd_trend(ts, trend_start = 1951)
# Reporting table with Total Change = slope * years
cd_summary(trn)
#> # A tibble: 1 × 7
#> Parameter Period Slope Years `Total Change` Unit `p-value`
#> <chr> <chr> <dbl> <int> <dbl> <chr> <dbl>
#> 1 Mean temperature Annual 0.128 10 1.3 °C 0.592
# Add region label for multi-AOI reports
cd_summary(trn, region_name = "Example AOI")
#> # A tibble: 1 × 8
#> Parameter Period Slope Years `Total Change` Unit `p-value` Region
#> <chr> <chr> <dbl> <int> <dbl> <chr> <dbl> <chr>
#> 1 Mean temperature Annual 0.128 10 1.3 °C 0.592 Example AOI
# Two trend windows: a Start column says which row is which
cd_summary(cd_trend(ts, trend_start = c(1951, 1956)))
#> # A tibble: 2 × 8
#> Parameter Period Start Slope Years `Total Change` Unit `p-value`
#> <chr> <chr> <dbl> <dbl> <int> <dbl> <chr> <dbl>
#> 1 Mean temperature Annual 1951 0.128 10 1.3 °C 0.592
#> 2 Mean temperature Annual 1956 0.543 5 2.7 °C 0.462
