Classify two regional rates independently, then document all nine combinations, denominators and missing regions.
Bivariate choropleths: map two rates with a readable joint legend
Make each variable a comparable regional rate
A bivariate choropleth gives each area one color based on two measurements. First establish a meaningful rate for each variable, with its own numerator, denominator, period and units. Coloring counties by raw counts mainly maps population size, while comparing a rate from 2024 with another from 2026 can imply a joint pattern that never existed at one time. Check whether the geography is identical for both data sets and whether boundary changes have been resolved. Single-variable choropleths explain why boundary version and denominator belong in the legend. If two measures cannot be made comparable, separate maps with explicit units are the honest choice.
Classify each axis before mixing color
A typical joint legend has three classes for the horizontal measure and three for the vertical measure. That yields nine named combinations, such as low–high, not nine unlabeled shades. Declare two cut points per variable and how exact boundary values are handled. The code uses lower-inclusive classes: a value equal to the first cut moves into the middle class. Choose cut points against the analytic question, then freeze them across panels. Recomputing quantiles on every filter action can cause a region's color to change even when its rate does not. Shared scales apply to map panels too. A 3×3 legend should label both axes, their directions and the numeric boundaries.
Separate missingness from low values
A region missing either measure has no joint class. Give it a separate visible symbol and a table row explaining which measure is missing. A zero is a valid numeric value only when the upstream measurement process really observed zero. Suppression of small counts is not zero, and imputing it can distort a rate. Heatmap missing cells face the same distinction. Reconcile the number of mapped, missing, suppressed and excluded regions before styling. If an area has a tiny denominator, attach count and uncertainty in a companion table so its saturated color is not mistaken for strong evidence.
Use the map for patterns, the table for values
Nine colors are hard to decode from memory, especially when several patches are similar or the map is viewed on a small display. Test the palette under common color-vision differences and in grayscale; provide class text and both exact rates on focus or in a linked table. A bivariate map can suggest a spatial association, but it does not establish that one measure causes the other. Large regions occupy more screen area regardless of population, and neighboring regions are not independent evidence by default. Accessible color and text alternatives should be part of the export, not an afterthought. Include the breakpoints, data period, geographic key and unmapped-count summary with every image.
Worked contract
from math import isfinite
def joint_rate_classes(regions: list[tuple[str, float | None, float | None]],
first_cuts: tuple[float, float],
second_cuts: tuple[float, float]):
if not (first_cuts[0] < first_cuts[1] and second_cuts[0] < second_cuts[1]):
raise ValueError("each pair of cuts must increase")
if len({region for region, _, _ in regions}) != len(regions):
raise ValueError("region keys must be unique")
cells = []
for region, first_rate, second_rate in regions:
if not region:
raise ValueError("region key is required")
if first_rate is None or second_rate is None:
cells.append((region, None, first_rate, second_rate))
continue
if not isfinite(first_rate) or not isfinite(second_rate):
raise ValueError("rates must be finite")
first_class = sum(first_rate >= cut for cut in first_cuts)
second_class = sum(second_rate >= cut for cut in second_cuts)
cells.append((region, (first_class, second_class),
first_rate, second_rate))
return cells
service_regions = [("ward-47", 12.0, 31.0),
("ward-59", 19.0, 45.0),
("ward-83", None, 24.0)]
classified = joint_rate_classes(service_regions, (12.0, 18.0), (25.0, 40.0))
assert classified[0][1] == (1, 1)
assert classified[1][1] == (2, 2)
assert classified[2][1] is NonePerformance and operating cost
Classifying R regions takes O(R) time and O(R) output space; the nine-color lookup is constant size. The function preserves exact rates and missingness alongside class coordinates, and its assertions pin the breakpoint tie rule. It assumes both inputs are already compatible rates. Validate numerators, denominators, units, boundary version and time window upstream before interpreting any mapped class.
Common Mistakes
- Mixing raw counts with rates in one joint legend.
- Recomputing class breaks separately for each period while comparing colors.
- Coloring a suppressed or absent rate as low.
- Shipping nine colors without numeric boundaries or an accessible table.
Validation drill
Classify 47 wards for two service rates. Report all nine cell counts plus missing regions, and test whether the map stays interpretable in grayscale.
