Maps predicted response values from stats::predict() output on a
ggOceanMaps::basemap(), either averaged over time (type = "mean"),
faceted by time (type = "annual"), or as the annual difference from each
cell's mean over time (type = "anomaly"), faceted by time.
Arguments
- pred
A prediction data frame from
predict(fit, newdata = ...), containing coordinate columns and the response column. If the response column is on the link scale (the defaultpredict()output, e.g. log density for a log-link family), it can be negative; combine with a suitablefill_limitsif you want to floor the colour scale, or usepredict(fit, newdata = ..., type = "response")for density-scale values.- crs
Coordinate reference system (projected, in metres).
- column
Character. Name of the response column. Default
"est".- type
Character.
"mean"(default),"annual"or"anomaly".- time_col
Character. Name of the time column (for
type = "annual"and"anomaly"). Default"year".- transform
Character. Fill-scale transformation, passed to
transforminggplot2::continuous_scale()(the successor to the now-deprecatedtransargument). Default"identity". Fortype = "anomaly","sqrt"is a signed square root.- fill_limits
Numeric vector of length two (either element may be
NA), passed tolimitsinggplot2::continuous_scale(). Values outside the limits are mapped toNAby ggplot2 and rendered as blank/grey cells. DefaultNULL: the scale's range is taken from the data, so no cells are dropped. Set e.g.c(0, NA)to floor a response-scale plot at zero.- anomaly
Character. Scale of the anomaly for
type = "anomaly":"max_percent"(default),"cell_percent"or"absolute". See Details.- xy_cols
Character vector of the coordinate columns. Default
c("X", "Y").- coord_multiplier
Numeric factor to convert coordinates to CRS units. Default
1000.- base_size
Numeric. Base font size. Default
11.
Details
For type = "anomaly", each cell's value in a year is compared with the mean
of that cell over all years, \(x_{c,t} - \bar{x}_c\), and expressed as set
by anomaly: "max_percent" (default) divides it by the largest cell mean
and multiplies by 100, so that all panels share one scale relative to the
densest cell and sparse cells do not produce large percentages;
"cell_percent" divides it by the cell's own mean (percent change of the
cell); "absolute" keeps the response units. The anomaly map uses a
diverging scale centred on zero; transform = "sqrt" applies a signed
square root, which keeps the sign and makes small differences visible.
Use column on the response scale (e.g. predict(..., type = "response")
or exp() of a log prediction) for an anomaly of density.
AI assistance
AI-assisted (model not recorded); not yet reviewed in full by the current model. Edited by Claude Opus 5.5 (Anthropic), 2026-11-24.
Examples
# \donttest{
mesh <- sdmTMB::make_mesh(sdmTMB::pcod, c("X", "Y"), cutoff = 20)
m <- sdmTMB::sdmTMB(
density ~ 0 + as.factor(year), data = sdmTMB::pcod, time = "year",
mesh = mesh, family = sdmTMB::tweedie()
)
nd <- sdmTMB::replicate_df(sdmTMB::qcs_grid, "year", unique(sdmTMB::pcod$year))
pred <- predict(m, newdata = nd, type = "response")
plot_prediction_map(pred, crs = 32609)
# }