Skip to contents

Creates a tibble with all represented combinations of factor variables in the data, and includes a model of model predictions across a key continuous variable (plot_by, defaults to "doy") while setting other continuous variables to their median. Because these plots are within a tibble framework, it is easy to filter to desired combinations of variables and plot those. (e.g., model might fit 20 years for 13 spatial units, tibble can rapidly be filtered to just the years of a desired spatial unit, or all spatial units of a desired year).

If model is a named list of mgcv models, the result is a combination of panel tibbles for each fitted model, with an additional column $model to identify the models used to generate each panel. This can make it easy to compare how modeling choices change predictions.

Usage

plot_seasonal_gam_panels(
  model,
  color_by = NULL,
  plot_by = "doy",
  across_increment = 1,
  quant_trimming = 0.01,
  include_cis = TRUE,
  plot_coverage = TRUE,
  breaks_x = 3,
  model_label = "model",
  labeler_x = VizSeasonalGams::doy_2md,
  verbose = TRUE
)

Arguments

model

A GAM model object from mgcv, or a named list of fitted mgcv models

color_by

Variable to color predictions by. Defaults to NULL, in which case curves are black and each panel has only one set of predictions. When used, color_by necessarily reduces dimensionalality of output by 1.

plot_by

A single string specifying the variable to plot across. Defaults to "doy".

across_increment

A numeric value specifying the increment for the plot_by variable. Defaults to 1.

quant_trimming

A numeric value between 0 and 1 defining quantile-based trimming – this provides a buffer between the outmost observations and the outmost plot predictions. Defaults to 0.01; increase if plot predictions at the edges are misleading.

include_cis

Should we plot the confidence envelope? Logical, defaults to TRUE

plot_coverage

Add histogram at bottom of each panel with data coverage? Logical, defaults to TRUE.

breaks_x

Approximate number of ticks to use on the X axis, useful to ensure text is legible. Numeric, defaults to 3. Because of quirks in how ggplot works (and the patchwork combination process), plots may not show exactly breaks_x number of ticks, but you can still manipulate actual tick number by changing breaks_x.

model_label

Name to apply to the model identifier column generated when providing a list of mgcv models to model argument.

labeler_x

Function used to apply x axis labels. Defaults to "doy_2md" which turns numeric day of year into month and day. A value of NULL will use identity.

verbose

Provide context? Logical, defaults to TRUE

Value

Tibble, with a column for each factor predictor in model. $.plot column contains the plot panels.