Skip to content
OpenChart

Choropleth

Color regions on a map by a value, from US states to world countries, with classed scales, projections and no-data fills.

A choropleth colors each region of a map by a value, such as a rate per state or an income per country. It shows which regions run high or low and whether neighbors cluster. Color suits rates and shares better than totals, because large regions draw the eye whatever their value.

Use a tile map when small states matter as much as large ones, and a bar chart when the reader needs to rank the regions or read exact values.

A basic choropleth

Set type to "map", pass a TopoJSON topology as geo.features, and join rows to its shapes with the key channel: each row’s key value is matched against a feature’s id. The color channel names the value to color by, and its title becomes the legend heading. With a quantitative color field the values fall into evenly spaced classes with round-number breaks, and the legend swatches use the same classes as the map.

Unemployment is highest in DC and lowest in SouthDakotaUnemployment rate by state (%)3.04.05.0Unemployment rate (%)Unemployment is highest in DC and lowest in SouthDakotaUnemployment rate by state (%)3.04.05.0Unemployment rate (%)
Unemployment rate by state. Source: Bureau of Labor Statistics, Local Area Unemployment Statistics; geography: US Census Bureau via us-atlas.
{
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 181 arcs; Copy includes it */},
    "projection": "albersUsa"
  },
  "data": [
    {
      "id": "01",
      "rate": 2.7
    },
    {
      "id": "02",
      "rate": 4.8
    },
    {
      "id": "04",
      "rate": 4.7
    },
    {
      "id": "05",
      "rate": 4.2
    },
    {
      "id": "06",
      "rate": 5.3
    },
    {
      "id": "08",
      "rate": 3.8
    },
    // … 45 more rows; Copy includes them
  ],
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "rate",
      "type": "quantitative",
      "format": ".1f",
      "title": "Unemployment rate (%)"
    }
  },
  "chrome": {
    "title": "Unemployment is highest in DC and lowest in South Dakota",
    "subtitle": "Unemployment rate by state (%)"
  }
}
import { GeoMap } from "@opendata-ai/openchart-react";
import type { GeoMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 51 rows; Copy includes them */];

const spec: GeoMapSpec = {
  data,
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 181 arcs; Copy includes it */},
    "projection": "albersUsa"
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "rate",
      "type": "quantitative",
      "format": ".1f",
      "title": "Unemployment rate (%)"
    }
  },
  "chrome": {
    "title": "Unemployment is highest in DC and lowest in South Dakota",
    "subtitle": "Unemployment rate by state (%)"
  }
};

export function Example() {
  return <GeoMap spec={spec} />;
}
<script setup lang="ts">
import { GeoMap } from "@opendata-ai/openchart-vue";
import type { GeoMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 51 rows; Copy includes them */];

const spec: GeoMapSpec = {
  data,
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 181 arcs; Copy includes it */},
    "projection": "albersUsa"
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "rate",
      "type": "quantitative",
      "format": ".1f",
      "title": "Unemployment rate (%)"
    }
  },
  "chrome": {
    "title": "Unemployment is highest in DC and lowest in South Dakota",
    "subtitle": "Unemployment rate by state (%)"
  }
};
</script>

<template>
  <GeoMap :spec="spec" />
</template>
<script lang="ts">
import { GeoMap } from "@opendata-ai/openchart-svelte";
import type { GeoMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 51 rows; Copy includes them */];

const spec: GeoMapSpec = {
  data,
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 181 arcs; Copy includes it */},
    "projection": "albersUsa"
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "rate",
      "type": "quantitative",
      "format": ".1f",
      "title": "Unemployment rate (%)"
    }
  },
  "chrome": {
    "title": "Unemployment is highest in DC and lowest in South Dakota",
    "subtitle": "Unemployment rate by state (%)"
  }
};
</script>

<GeoMap {spec} />
import { createGeoMap } from "@opendata-ai/openchart-vanilla";
import type { GeoMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 51 rows; Copy includes them */];

const spec: GeoMapSpec = {
  data,
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 181 arcs; Copy includes it */},
    "projection": "albersUsa"
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "rate",
      "type": "quantitative",
      "format": ".1f",
      "title": "Unemployment rate (%)"
    }
  },
  "chrome": {
    "title": "Unemployment is highest in DC and lowest in South Dakota",
    "subtitle": "Unemployment rate by state (%)"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createGeoMap(container, spec);

Hovering a state outlines it and brings it to the front. Hovering a legend swatch dims the states outside that class.

Passing the geography

The maps on this page draw on a reduced copy of the atlas files, simplified so the page stays small. Their code tabs fold the topology to a comment, and Copy writes it out in full. In your own code, import the topology from us-atlas or world-atlas and pass it as it is:

import states from "us-atlas/states-10m.json";

const spec = {
  type: "map",
  geo: { features: states, projection: "albersUsa" },
  data: rows, // one row per state, with a two-digit FIPS code in `id`
  encoding: {
    key: { field: "id", type: "nominal" },
    color: { field: "rate", type: "quantitative", title: "Unemployment rate (%)" },
  },
};

geo.projection picks the projection. Left out, it is inferred from the topology: coordinates already in pixels get "identity", a span of more than 200 degrees of longitude gets "equalEarth", and anything else gets "albersUsa". The states file crosses 200 degrees because the Aleutian Islands reach past the 180th meridian, so set "albersUsa" for it. That projection leaves out Puerto Rico and the other territories.

A world map

The same spec draws the world with world-atlas, whose features are keyed by ISO 3166-1 numeric codes. "equalEarth" keeps each country’s area true to its size; "mercator" is also available. Countries without a row get the no-data fill, and the legend adds a “No data” swatch beside the color classes. legend.position: "right" moves the legend beside the map.

GDP per capita for 30 countries. This chart is drawn in the browser.

GDP per capita for 30 countries; the rest show the no-data fill. Antarctica is left out. Source: World Bank, GDP per capita (current US$), approximate values; geography: Natural Earth via world-atlas.
{
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 512 arcs; Copy includes it */},
    "projection": "equalEarth"
  },
  "data": [
    {
      "id": "840",
      "gdp": 80035
    },
    {
      "id": "156",
      "gdp": 12720
    },
    {
      "id": "392",
      "gdp": 33815
    },
    {
      "id": "276",
      "gdp": 51384
    },
    {
      "id": "356",
      "gdp": 2485
    },
    {
      "id": "826",
      "gdp": 46125
    },
    // … 24 more rows; Copy includes them
  ],
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$,.0f",
      "title": "GDP per capita"
    }
  },
  "legend": {
    "position": "right"
  },
  "chrome": {
    "title": "Switzerland tops these 30 countries at $99,994",
    "subtitle": "GDP per capita, current US dollars, 2023"
  }
}
import { GeoMap } from "@opendata-ai/openchart-react";
import type { GeoMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 30 rows; Copy includes them */];

const spec: GeoMapSpec = {
  data,
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 512 arcs; Copy includes it */},
    "projection": "equalEarth"
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$,.0f",
      "title": "GDP per capita"
    }
  },
  "legend": {
    "position": "right"
  },
  "chrome": {
    "title": "Switzerland tops these 30 countries at $99,994",
    "subtitle": "GDP per capita, current US dollars, 2023"
  }
};

export function Example() {
  return <GeoMap spec={spec} />;
}
<script setup lang="ts">
import { GeoMap } from "@opendata-ai/openchart-vue";
import type { GeoMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 30 rows; Copy includes them */];

const spec: GeoMapSpec = {
  data,
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 512 arcs; Copy includes it */},
    "projection": "equalEarth"
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$,.0f",
      "title": "GDP per capita"
    }
  },
  "legend": {
    "position": "right"
  },
  "chrome": {
    "title": "Switzerland tops these 30 countries at $99,994",
    "subtitle": "GDP per capita, current US dollars, 2023"
  }
};
</script>

<template>
  <GeoMap :spec="spec" />
</template>
<script lang="ts">
import { GeoMap } from "@opendata-ai/openchart-svelte";
import type { GeoMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 30 rows; Copy includes them */];

const spec: GeoMapSpec = {
  data,
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 512 arcs; Copy includes it */},
    "projection": "equalEarth"
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$,.0f",
      "title": "GDP per capita"
    }
  },
  "legend": {
    "position": "right"
  },
  "chrome": {
    "title": "Switzerland tops these 30 countries at $99,994",
    "subtitle": "GDP per capita, current US dollars, 2023"
  }
};
</script>

<GeoMap {spec} />
import { createGeoMap } from "@opendata-ai/openchart-vanilla";
import type { GeoMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 30 rows; Copy includes them */];

const spec: GeoMapSpec = {
  data,
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 512 arcs; Copy includes it */},
    "projection": "equalEarth"
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$,.0f",
      "title": "GDP per capita"
    }
  },
  "legend": {
    "position": "right"
  },
  "chrome": {
    "title": "Switzerland tops these 30 countries at $99,994",
    "subtitle": "GDP per capita, current US dollars, 2023"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createGeoMap(container, spec);

A region, a diverging scale and a join by name

A map draws only the features in its topology, so passing a subset of the states maps one region and fits it to the frame. This one keeps ten Southeast states.

geo.idField joins on a feature property instead of the id. The us-atlas states carry a name property, so rows keyed by state name join with idField: "name". A diverging scheme such as "redBlue" suits values on both sides of zero: the classes are spread evenly around zero, with an odd number of them so the middle class is labeled as near zero.

Florida grew fastest of these five states; West VirginiashrankPopulation change, April 2020 to July 2024 (%)No dataPopulation change (%)Near zero: −2.5 to <+2.5< −7.5−7.5 – < −2.5−2.5 – < +2.5+2.5 – < +7.5≥ +7.5Florida grew fastest of these five states; West VirginiashrankPopulation change, April 2020 to July 2024 (%)No dataPopulation change (%)Near zero: −2.5 to <+2.5< −7.5−7.5 – < −2.5−2.5 – < +2.5+2.5 – < +7.5≥ +7.5
Population change in ten Southeast states, joined by state name. The dataset covers 5 of them. Source: U.S. Census Bureau Population Estimates; geography: US Census Bureau via us-atlas.
{
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 42 arcs; Copy includes it */},
    "projection": "albersUsa",
    "idField": "name"
  },
  "data": [
    {
      "state": "Florida",
      "change": 8.9
    },
    {
      "state": "South Carolina",
      "change": 6.8
    },
    {
      "state": "North Carolina",
      "change": 5.9
    },
    {
      "state": "Georgia",
      "change": 4.1
    },
    {
      "state": "West Virginia",
      "change": -1.5
    }
  ],
  "encoding": {
    "key": {
      "field": "state",
      "type": "nominal"
    },
    "color": {
      "field": "change",
      "type": "quantitative",
      "format": "+.1f",
      "title": "Population change (%)",
      "scale": {
        "scheme": "redBlue"
      }
    }
  },
  "legend": {
    "position": "right"
  },
  "chrome": {
    "title": "Florida grew fastest of these five states; West Virginia shrank",
    "subtitle": "Population change, April 2020 to July 2024 (%)"
  }
}
import { GeoMap } from "@opendata-ai/openchart-react";
import type { GeoMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: GeoMapSpec = {
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 42 arcs; Copy includes it */},
    "projection": "albersUsa",
    "idField": "name"
  },
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "key": {
      "field": "state",
      "type": "nominal"
    },
    "color": {
      "field": "change",
      "type": "quantitative",
      "format": "+.1f",
      "title": "Population change (%)",
      "scale": {
        "scheme": "redBlue"
      }
    }
  },
  "legend": {
    "position": "right"
  },
  "chrome": {
    "title": "Florida grew fastest of these five states; West Virginia shrank",
    "subtitle": "Population change, April 2020 to July 2024 (%)"
  }
};

export function Example() {
  return <GeoMap spec={spec} />;
}
<script setup lang="ts">
import { GeoMap } from "@opendata-ai/openchart-vue";
import type { GeoMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: GeoMapSpec = {
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 42 arcs; Copy includes it */},
    "projection": "albersUsa",
    "idField": "name"
  },
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "key": {
      "field": "state",
      "type": "nominal"
    },
    "color": {
      "field": "change",
      "type": "quantitative",
      "format": "+.1f",
      "title": "Population change (%)",
      "scale": {
        "scheme": "redBlue"
      }
    }
  },
  "legend": {
    "position": "right"
  },
  "chrome": {
    "title": "Florida grew fastest of these five states; West Virginia shrank",
    "subtitle": "Population change, April 2020 to July 2024 (%)"
  }
};
</script>

<template>
  <GeoMap :spec="spec" />
</template>
<script lang="ts">
import { GeoMap } from "@opendata-ai/openchart-svelte";
import type { GeoMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: GeoMapSpec = {
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 42 arcs; Copy includes it */},
    "projection": "albersUsa",
    "idField": "name"
  },
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "key": {
      "field": "state",
      "type": "nominal"
    },
    "color": {
      "field": "change",
      "type": "quantitative",
      "format": "+.1f",
      "title": "Population change (%)",
      "scale": {
        "scheme": "redBlue"
      }
    }
  },
  "legend": {
    "position": "right"
  },
  "chrome": {
    "title": "Florida grew fastest of these five states; West Virginia shrank",
    "subtitle": "Population change, April 2020 to July 2024 (%)"
  }
};
</script>

<GeoMap {spec} />
import { createGeoMap } from "@opendata-ai/openchart-vanilla";
import type { GeoMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: GeoMapSpec = {
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 42 arcs; Copy includes it */},
    "projection": "albersUsa",
    "idField": "name"
  },
  "data": [/* 5 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "key": {
      "field": "state",
      "type": "nominal"
    },
    "color": {
      "field": "change",
      "type": "quantitative",
      "format": "+.1f",
      "title": "Population change (%)",
      "scale": {
        "scheme": "redBlue"
      }
    }
  },
  "legend": {
    "position": "right"
  },
  "chrome": {
    "title": "Florida grew fastest of these five states; West Virginia shrank",
    "subtitle": "Population change, April 2020 to July 2024 (%)"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createGeoMap(container, spec);

Classes default to evenly spaced breaks. scale: { type: "quantile" } puts the same number of regions in each class instead, which suits skewed data but moves the breaks whenever the data changes.

Over time

encoding.time plays the map through periods, recoloring each region one period at a time with the classes and legend fixed for the whole run. The color must be quantitative. The time-lapse map page covers the spec, missing values and the period label.

Fields that matter

Field What it does
type "map" selects this visualization.
geo.features The TopoJSON topology to draw.
geo.projection "albersUsa", "equalEarth", "mercator" or "identity". Inferred when left out.
geo.idField The feature property to join on. Default "id".
encoding.key The data field matched against each feature’s id.
encoding.color The value that colors each region; title heads the legend, format sets its numbers.
encoding.color.scale scheme for the colors, type for quantile or threshold classes.
legend.position Where the legend sits, such as "right".