Join measures to the right polygons, use a stated denominator, and distinguish unmapped places from zero-valued regions.
Choropleth maps: normalize counts and audit boundary coverage
Area color is not an event count
A choropleth fills geographic regions according to a measure. Large polygons occupy more pixels and can dominate attention even when they contain few people or events. Raw incident counts often track exposure, such as population or active deliveries, more than risk. For a comparable rate, carry numerator and denominator for each polygon and specify the period. Exposure-based rates explain why 8 incidents across 47,000 trips differ from 8 across 470 trips. A map can still show counts when workload is the question; label it as a count map.
Join by stable region identity
Names drift, abbreviations collide, and administrative boundaries change. Join facts to geometry with stable region IDs and a boundary version. Report unmatched fact IDs, polygons with no measure, duplicate assignments and overlapping boundaries before rendering. Spatial joins are a separate operation from coloring polygons; they can duplicate a record if geometries overlap. If one region splits midyear, a before-after map needs a common boundary basis or an explicit break. Do not let a chart library silently drop unmatched regions.
Projection and extent shape perception
A projection transforms coordinates into map space. It can distort area, shape or distance; no flat map preserves everything. For regional comparison, keep the same projection, extent and viewport across panels, and avoid interpreting the visible area of a polygon as its population. Insets for distant regions need clear labels and scale context. If exact comparison of rates matters more than location, provide a sorted bar chart alongside the map. Choose the visual that serves the question, not merely the available geometry.
Class breaks are an editorial decision
Equal-width bins, quantile bins and fixed policy thresholds answer different questions. A quantile palette can assign different colors to tiny numeric differences when many regions cluster tightly; fixed thresholds can leave some colors unused. Print numeric breakpoints and keep them stable when comparing dates. Use a separate treatment for missing data and low-exposure suppression. Color-domain rules carry over to map legends. Keep the original rate in the accessible table and tooltip; color bins are a summary, not the data.
Protect sensitive locations
Very small denominators can make rates unstable and expose information about a few people or facilities. Define a minimum publishable group size, aggregate or suppress as appropriate, and show a visible suppressed state. Do not infer that a blank region has zero risk. Location privacy and small-sample display belong to the same release review. Test a region with no geometry, a polygon with no observation, a zero numerator and a zero denominator separately.
Worked contract
def regional_rates(
boundary_ids: set[str],
incident_counts: dict[str, tuple[int, int]]
) -> dict[str, tuple[str, float | None]]:
unknown = set(incident_counts) - boundary_ids
if unknown:
raise ValueError(f"facts without geometry: {sorted(unknown)}")
result = {}
for region_id in boundary_ids:
if region_id not in incident_counts:
result[region_id] = ("missing", None)
continue
incidents, trips = incident_counts[region_id]
if not 0 <= incidents <= trips:
raise ValueError("invalid regional counts")
result[region_id] = ("no-exposure", None) if trips == 0 else (
"observed", incidents / trips)
return result
rates = regional_rates({"zone-47", "zone-81", "zone-94"},
{"zone-47": (8, 470), "zone-81": (0, 81)})
assert rates["zone-47"][1] == 8 / 470
assert rates["zone-81"] == ("observed", 0.0)
assert rates["zone-94"] == ("missing", None)Performance and operating cost
For B boundary IDs and M measured regions, this join-and-rate check takes O(B + M) expected time and O(B) output space using hash sets. Rendering cost depends on polygon vertex count, projection and viewport clipping, none of which this code performs. Simplify geometry only to a documented tolerance and keep an exact source for hit tests. A cached tile or geometry file must carry the same boundary version as the measures. The code distinguishes zero and missing; a real publication layer also enforces suppression and uncertainty policy.
Common Mistakes
- Coloring raw counts as if the map showed per-person or per-trip risk.
- Joining on human-readable region names without checking unmatched and duplicated keys.
- Treating a missing polygon or missing measure as zero.
- Changing map bounds or class breaks between comparison dates.
Validation drill
Map 23 service zones with one split boundary, one missing measure and one zone below the publishable exposure threshold. Reconcile region IDs and rates before drawing polygons; add a sorted rate table for exact comparison.
Read next
- Heatmaps: make missing cells, rates and color domains explicit
- Uncertainty on charts: show denominators and intervals beside estimates
- Spatial joins: polygons, boundaries and duplicate matches
- Spatial aggregation: exposure, unstable cells and location privacy
Continue this visualization path
- Hexbin density: count overlapping points without hiding exposure
- Proportional-symbol maps: size circles by area, not radius
- Map boundaries: handle antimeridian crossings before drawing routes
- Bivariate choropleths: map two rates with a readable joint legend
- Contour plots: respect measured grids and interpolation boundaries
- Dot-density maps: fixed dot value, reproducible placement and area meaning
