Skip to contents

Produces five types of visualization for climasus_spacetime_bayes and climasus_spacetime_exceedance objects returned by sus_mod_spacetime_bayes() and sus_mod_spacetime_exceedance(): choropleth maps of relative risk, temporal trend charts, space-time interaction heatmaps, exceedance probability maps, and fixed-effect forest plots. Static ggplot2 output is returned by default; set interactive = TRUE for plotly::ggplotly() output.

Usage

sus_mod_plot_spacetime(
  x,
  type = c("rr_map", "temporal", "interaction", "exceedance", "coef"),
  municipalities = NULL,
  time_point = NULL,
  time_range = NULL,
  threshold = 1,
  facet_time = FALSE,
  palette = "RdYlBu",
  title = NULL,
  base_size = 11,
  interactive = FALSE,
  lang = "pt",
  ...
)

Arguments

x

A climasus_spacetime_bayes object from sus_mod_spacetime_bayes() or a climasus_spacetime_exceedance object from sus_mod_spacetime_exceedance().

type

Character. One of "rr_map" (default), "temporal", "interaction", "exceedance", "coef". See Plot types.

municipalities

An sf polygon object with a code_muni column (7-digit IBGE code). Required for type = "rr_map" and type = "exceedance". Typically from geobr::read_municipality().

time_point

Integer or NULL. Single time index to display in type = "rr_map". Ignored when facet_time = TRUE or for other types. Default NULL (aggregate mean across all periods).

time_range

Integer vector of length 2 (c(t_start, t_end)) to restrict the time axis in type = "temporal" and type = "interaction". Default NULL (all periods).

threshold

Numeric. RR threshold used to select the exceedance layer from x$exceedance when type = "exceedance". Default 1.0.

facet_time

Logical. When TRUE and type = "rr_map", produces a faceted map with one panel per time period. Default FALSE.

palette

Character. Name of a diverging RColorBrewer palette for RR maps (e.g. "RdYlBu", "RdBu", "PuOr"). Default "RdYlBu".

title

Character or NULL. Custom plot title. NULL uses a multilingual default.

base_size

Numeric. Base font size for ggplot2 themes. Default 11.

interactive

Logical. TRUE wraps the ggplot object with plotly::ggplotly() (requires plotly). Default FALSE.

lang

Character. Language for axis labels and titles: "pt" (default), "en", "es".

...

Currently unused; reserved for future arguments.

Value

A ggplot object (or plotly object when interactive = TRUE).

Plot types (type)

"rr_map"

Choropleth map of the posterior mean relative risk (rr_mean) merged with the municipalities sf polygon layer. Uses a diverging colour scale centred at 1.0. Municipalities where the entire 95\ Supply time_point to show a single period; set facet_time = TRUE to produce one facet per period; leave both as defaults to display the mean across all periods. Requires municipalities.

"temporal"

Line chart of the population-averaged posterior mean RR (aggregated across municipalities) with a shaded 95\ interval ribbon over time. Supply time_range to restrict the displayed periods.

"interaction"

Tile heatmap of the space-time interaction term (gamma_mean) with municipalities on the y-axis and time periods on the x-axis. Requires x$interaction in the input object. Supply time_range to restrict columns.

"exceedance"

Choropleth map of the exceedance probability P(RR > threshold). Requires a climasus_spacetime_exceedance object (or a climasus_spacetime_bayes that has an $exceedance slot). Requires municipalities.

"coef"

Horizontal forest plot of the fixed-effect posterior summaries (x$fixed). A dashed vertical reference line marks zero.

References

Knorr-Held, L. (2000). Bayesian modelling of inseparable space-time variation in disease risk. Statistics in Medicine, 19(17-18), 2555-2567. doi:10.1002/sim.1030

Blangiardo, M. & Cameletti, M. (2015). Spatial and Spatio-temporal Bayesian Models with R-INLA. Wiley. doi:10.1002/9781118950203

Examples

if (FALSE) { # \dontrun{
library(climasus4r)
library(geobr)

shp <- geobr::read_municipality(code_muni = "all", year = 2022)

fit <- sus_mod_spacetime_bayes(
  df         = agg,
  outcome    = "deaths",
  covariates = c("temp_mean", "prec_total"),
  offset     = "expected"
)

# Choropleth map: mean RR across all periods
sus_mod_plot_spacetime(fit, municipalities = shp, type = "rr_map")

# Choropleth for a single period (t = 3)
sus_mod_plot_spacetime(fit, municipalities = shp, type = "rr_map",
                       time_point = 3L)

# Faceted map
sus_mod_plot_spacetime(fit, municipalities = shp, type = "rr_map",
                       facet_time = TRUE)

# Temporal trend
sus_mod_plot_spacetime(fit, type = "temporal", lang = "en")

# Space-time interaction heatmap
sus_mod_plot_spacetime(fit, type = "interaction")

# Exceedance probability (requires climasus_spacetime_exceedance input)
exc <- sus_mod_spacetime_exceedance(fit, thresholds = c(1.0, 1.5, 2.0))
sus_mod_plot_spacetime(exc, municipalities = shp, type = "exceedance",
                       threshold = 1.5)

# Fixed-effect forest plot
sus_mod_plot_spacetime(fit, type = "coef", lang = "en")
} # }