Plot conditional effects of sdmTMB models
Source:R/conditional-effects.R
plot.sdmTMB_conditional_effects.RdDraws the output of conditional_effects(): one row per model (with the
model name as a heading when there are several) and one panel per term, on
the response scale with free y axes. Continuous terms are a line with a
confidence ribbon and a rug of the values at observations with a positive
response; factors (e.g. gear type or year) are point ranges. A grey vertical
line marks the reference value of each term. Panel slots are aligned across
models, so the same term lines up in every row; a model without a term
leaves its slot empty.
Usage
# S3 method for class 'sdmTMB_conditional_effects'
plot(
x,
fit = NULL,
data = NULL,
response = NULL,
y_lab = "Predicted response",
base_size = 9,
widths = NULL,
...
)Arguments
- x
An
sdmTMB_conditional_effectsobject fromconditional_effects().- fit
Optional. The fitted model, or the list of models passed to
conditional_effects(), for the rug. The rug is drawn only whendataorfitis given.- data
Optional data frame for the rug, with the continuous variables and the response. Overrides
fit.- response
Character. Name of the response column in
datafor the rug (positive values only). Taken from the model formula whenfitis given.- y_lab
Character. y-axis label. Default
"Predicted response".- base_size
Numeric. Base font size. Default
9.- widths
Optional named numeric vector of relative panel widths by term (variable name). By default continuous panels are 1.3 wide and factor panels grow with the number of levels. Factor labels longer than four characters are slanted when together they would crowd the axis.
- ...
Not used.
AI assistance
Written with Claude Opus 5.5 (Anthropic); reviewed in full by Claude Opus 5.5 (Anthropic), 2026-11-17.
Examples
# \donttest{
d <- subset(sebastes, year >= 2021 & cruiseseries %in% c("EcoS", "EggaN"))
mesh <- sdmTMB::make_mesh(d, c("X", "Y"), cutoff = 80)
m <- sdmTMB::sdmTMB(
density ~ s(depth, k = 5) + geartype,
data = d, mesh = mesh, family = sdmTMB::tweedie()
)
eff <- conditional_effects(m, se_fit = FALSE)
plot(eff, fit = m, y_lab = "Density (kg/nmi^2)")
# }