Skip to contents

Walks polys once and renders one ggplot facet per year for columns named <prefix>_<year>.

Usage

morie_tps_render_yearly_grid(
  polys,
  prefix = "ASSAULT_RATE",
  years = 2014:2024,
  cmap = "Reds",
  outfile = NULL,
  ncols = 4L
)

Arguments

polys

Polygon data.frame (see morie_tps_render_choropleth).

prefix

Column-name prefix (default "ASSAULT_RATE").

years

Integer vector of years (default 2014:2024).

cmap

Sequential palette name (default "Reds").

outfile

Optional output path.

ncols

Number of facet columns.

Value

A ggplot (when ggplot2 is loaded) or invisible(NULL) for the base-R fallback.

Examples

ring <- lapply(seq(0, 2 * pi, length.out = 8), function(a) {
  list(-79.40 + 0.02 * cos(a), 43.70 + 0.01 * sin(a))
})
polys <- data.frame(HOOD_ID = 1, RATE = 5)
polys$geometry <- list(ring)
polys$ASSAULT_RATE_2023 <- 4; polys$ASSAULT_RATE_2024 <- 5
out <- morie_tps_render_yearly_grid(polys, prefix = "ASSAULT_RATE",
                                    years = 2023:2024,
                                    outfile = tempfile(fileext = ".png"))