view source

Choropleth and Proportional Symbol Maps for Data

skill

Make choropleth and proportional-symbol maps that read correctly: rates, classes, colors, projection, boundary joins. Use for any map of data by area.

Apache-2.0 Python with geopandas, matplotlib and mapclassify, or plotly, through uv run. Boundary files are downloaded, so network access is needed once.

agents that use this skill

instructions

Overview

Use this skill when data is shown on a map by area or by place: a choropleth (areas shaded by value), a proportional-symbol map, a dot-density map or a cartogram (a map that resizes each area by its value). The outcome is a map that shows a rate where a rate is meant, uses an equal-area projection for shaded areas, joins on codes without silent loss, and says where data is missing. The deliverable is the rendered map plus the join and class checks, looked at before it is shared.

Mental model

  • A choropleth gives every unit of an area the same color, so large units dominate the eye whatever their population. The map shows geography first and the data second.
  • A map answers where. If the question is how much or which is larger, a sorted bar chart often answers better; Datawrapper lists tables, text and other charts for precise comparison, correlation, and regions too small to see.
  • Data aggregated to areas describes the areas, not the people in them, and the result depends on where the lines were drawn.

Rules

Decide whether a map is the right form

DataForm
A rate or ratio for administrative areasChoropleth
Counts, or values for specific placesProportional symbols, dot density or a cartogram
A few places to locateLocator map
Precise comparison between areasSorted bars or a table
Phenomenon that ignores unit borders, such as soil or diseaseDot density, symbols or cartogram

Show rates, not counts

Axis Maps: never use a choropleth with raw counts; use rates or ratios such as people per square mile. A count of people by county mostly redraws the population map; Datawrapper warns that a symbol map of counts often just shows where most people live. Compute the rate from a numerator and denominator that cover the same area and period. A unit with a tiny denominator, such as Antarctica in GDP per person, lands in the darkest class: drop or flag such units.

Classes

MethodUseWatch for
Equal intervalValues spread evenlySkew or outliers leave empty classes
QuantilesEqual counts per classClass ranges vary widely; similar values split
Natural breaksMinimizes variance inside classesBreaks differ per dataset, so maps cannot be compared
ManualMeaningful thresholds, or one scheme across a series of mapsNeeds a reason for each break
  • Use 3 to 7 classes (Axis Maps). More classes generalize less but are harder to read. Look at a histogram for clusters and gaps first.
  • Unclassed maps give every value its own color; they show noise, matching a color to the legend is hard, and they print poorly. Use classes when readers must extract values.
  • Draw the same data with a second method. If the story changes, say so.

Color and legend

  • Sequential scale for low to high, darker for larger. Diverging scale only when the midpoint means something, such as zero or the mean; the middle class is the lightest (Datawrapper).
  • Ordinal data fits a classed choropleth with a sequential scheme.
  • ColorBrewer offers 3 to 12 classes; the maximum depends on the scheme type: 9 for sequential, 11 for diverging, 12 for qualitative (its scheme data). It can filter to colorblind safe, print friendly and photocopy safe schemes.
  • The legend shows the lowest and highest value plus two to four values between. A classed map labels the class breaks. A diverging legend also shows the center (Datawrapper). Name the unit and the period. Exact values go in a tooltip or table.

Projection

Choropleth and dot-density maps need an equal-area projection, because area carries the data (Axis Maps). Web Mercator is common on web maps but is not suitable for thematic maps beyond local areas: Greenland looks about as big as South America, which is eight times larger (Axis Maps). Compromise projections suit world maps but not density data. Equal-area examples named by Axis Maps: Albers Equal Area Conic, Cylindrical Equal Area. In geopandas, to_crs changes coordinates and set_crs only labels them; the geopandas guide reprojects the USA to ESRI:102003, an Albers projection, and ESRI:54009 (World Mollweide) is an equal-area choice for the world. In plotly, update_geos with projection_type="sinusoidal" gives an equal-area world view.

Small and large areas

  • Large, sparsely populated units dominate. A population cartogram gives weight to populated areas but is harder to read for unfamiliar geography (Datawrapper).
  • Units too small to see do not belong in a choropleth: use a table, text or another chart for them.
  • Prefer the smallest units the data supports, such as counties over states (Datawrapper).

Proportional symbols

Use symbols for counts and for data tied to points. Overlap is the main fault. Datawrapper's fixes: lower the maximum size, lower fill opacity, add outlines, group nearby symbols. Always draw a size legend with values. Scale the symbol's area, not its radius or height, to the value: a place with twice the value gets twice the area (Axis Maps).

Join on codes, not names

Join the table to the boundaries on a standard code, then check. Some rows of Natural Earth's country file carry -99 in ISO_A3 (France, Norway, N. Cyprus, Somaliland and Kosovo in the 110m file), so test for -99 before joining. ADM0_A3, Natural Earth's own three-letter admin code, has a value for all 177 rows of that file and is unique. Names differ too: "Dem. Rep. Congo", "Bosnia and Herz.". Call merge from the GeoDataFrame, since a pandas frame merged with a GeoDataFrame as right argument returns a plain DataFrame (geopandas docs). After the merge, print the rows that matched on neither side and stop if any remain unexplained.

Boundary data and licences

SourceTerms
Natural EarthPublic domain; a few datasets carry third-party limits
US Census cartographic boundary filesSimplified for small-scale thematic mapping; check the page for terms
Eurostat GISCOSource acknowledged, not for commercial use; legend notice "© EuroGeographics for the administrative boundaries"
geoBoundariesgbOpen under CC BY 4.0 or ODbL, attribution required; each boundary lists its source and licence
GADMFree for academic and other non-commercial use; redistribution and commercial use need permission
OpenStreetMapODbL, credit required, derived databases stay under the same licence

Write the source and licence on the map or in its caption.

Missing data

Missing is not zero. geopandas ignores features with missing values unless missing_kwds sets a style and label; give them a neutral grey and a "No data" legend entry. State the share of units missing.

Caveats to state

  • Ecological fallacy: a pattern between areas need not hold for individuals. Robinson (1950) found the state-level correlation between foreign birth and illiteracy negative while the individual-level one was positive.
  • Modifiable areal unit problem: results change with the scale (aggregation level) and the zoning (how areas are grouped). Run the analysis at a second level or zoning when the claim matters (Openshaw 1984).

Build and verify

Download boundaries into an empty directory and run from another: curl -sSL -o ne.zip https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip, then unzip. With geopandas, run uv run --with geopandas --with matplotlib --with mapclassify python script.py, using read_file, to_crs, then plot with column, scheme="quantiles", k=5, cmap, legend=True and missing_kwds. With plotly, run uv run --with geopandas --with plotly --with pandas python script.py with px.choropleth(locations=..., color=...); it draws a continuous scale, so bin first for classes, and the HTML output is several megabytes.

When the user cannot be asked, assume a rate per capita, five quantile classes and an equal-area projection, and say so.

Examples

Counts to rates. Bad: cases per county, darkest where cities are. Good: cases per 100,000 residents, five classes, a note naming the period.

Join loss. Bad: merge on ISO_A3; France and Norway vanish as blank shapes. Good: merge on ADM0_A3, then print unmatched rows on both sides.

Mercator to equal-area. Bad: a world choropleth in Web Mercator that inflates the far north. Good: the same data in an equal-area projection with a legend and source line.

Output format

  • The map file and the table behind it.
  • Rate definition, classes and method, projection, boundary source and licence.
  • Unmatched and missing counts, and the caveat that applies.

Checklist

  • A map is the right form; the value is a rate for shaded areas.
  • The rate has numerator and denominator for the same area and period; tiny denominators are flagged.
  • 3 to 7 classes; a second method was compared; the scale type fits the data.
  • The projection is equal-area for shaded areas.
  • The join used codes; unmatched rows were printed and resolved.
  • Missing data is grey, labeled and counted.
  • The legend has unit, period and class breaks; source and licence are on the map.
  • The rendered image was opened and looked at.

Composition / References

Scope limits: spatial statistics, geocoding, slippy web maps and chart form in general are separate jobs.