Polygon choropleth map for Toronto (158 wards)
Source:R/tps_render.R
morie_tps_render_choropleth.RdRenders 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.frameortibblewith columnsgeometry(list-column of N x 2 lon/lat matrices) and the metric column named inrate_col. An optionalHOOD_IDorAREA_IDcolumn 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). WhenNULL, 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.