Skip to contents

Renders a sequential-colour choropleth from a polygon data.frame carrying one row per neighbourhood with a list-column of WGS84 (lon, lat) rings (geometry) and a numeric rate_col. This signature deliberately matches what rmorie::morie_fetch("https://.../NeighbourhoodCrimeRates...", format = "geojson") returns once unrolled.

Usage

morie_tps_render_choropleth(
  polys,
  rate_col = "ASSAULT_RATE_2024",
  title = NULL,
  cmap = "YlOrRd",
  outfile = NULL,
  fig_w = 12,
  fig_h = 7,
  show_ids = TRUE,
  border_color = "#1a1a1a",
  border_lw = 0.7
)

Arguments

polys

A data.frame or tibble with columns geometry (list-column of N x 2 lon/lat matrices) and the metric column named in rate_col. An optional HOOD_ID or AREA_ID column drives the show-IDs labels.

rate_col

Name of the metric column. Default "ASSAULT_RATE_2024".

title

Plot title; defaults to a Hohl-2024-style auto-label.

cmap

Sequential colour palette name (default "YlOrRd").

outfile

Path to write the image (.png, .pdf, .svg). When NULL, the function returns the plot object without writing.

fig_w, fig_h

Figure size in inches.

show_ids

When TRUE (default), draw small numeric polygon-ID labels at each ward centroid.

border_color

Polygon edge colour.

border_lw

Polygon edge linewidth.

Value

A ggplot object (when ggplot2 is loaded) or invisible(NULL) for the base-R fallback; the file path is returned invisibly when outfile is supplied.

Details

When ggplot2 is available the render uses geom_polygon + scale_fill_distiller; otherwise the base R polygon() primitive is used.

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)
out <- morie_tps_render_choropleth(polys, rate_col = "RATE",
                                   outfile = tempfile(fileext = ".png"))