Skip to content
OpenChart

Geographic labels

Name the regions and points on a map from data, and anchor authored callouts to features that hold as readers zoom.

A map without names asks the reader to know the geography. Geographic labels put names on regions and points from the data, and callouts add a written finding anchored to a place. Labels are off until a spec asks for them.

Labels name a few places and leave the rest to the colors. When the reader needs every value by name, a data table lists them all.

Region names

Add a text channel to the map’s encoding. The label comes from the field in the region’s data row, or, when the row has no such field, from the topology property of the same name. The us-atlas states carry a name property, so text: { field: "name" } labels every state. When labels collide, the ones with a higher textPriority value place first; here that is the unemployment rate.

State names on an unemployment map. This chart is drawn in the browser.

State names on an unemployment map. 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 (%)"
    },
    "text": {
      "field": "name",
      "type": "nominal"
    },
    "textPriority": {
      "field": "rate",
      "type": "quantitative"
    }
  },
  "chrome": {
    "title": "Every state name that fits, placed highest rate first",
    "subtitle": "Unemployment rate by state (%); names come from the atlas"
  }
}
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 (%)"
    },
    "text": {
      "field": "name",
      "type": "nominal"
    },
    "textPriority": {
      "field": "rate",
      "type": "quantitative"
    }
  },
  "chrome": {
    "title": "Every state name that fits, placed highest rate first",
    "subtitle": "Unemployment rate by state (%); names come from the atlas"
  }
};

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 (%)"
    },
    "text": {
      "field": "name",
      "type": "nominal"
    },
    "textPriority": {
      "field": "rate",
      "type": "quantitative"
    }
  },
  "chrome": {
    "title": "Every state name that fits, placed highest rate first",
    "subtitle": "Unemployment rate by state (%); names come from the atlas"
  }
};
</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 (%)"
    },
    "text": {
      "field": "name",
      "type": "nominal"
    },
    "textPriority": {
      "field": "rate",
      "type": "quantitative"
    }
  },
  "chrome": {
    "title": "Every state name that fits, placed highest rate first",
    "subtitle": "Unemployment rate by state (%); names come from the atlas"
  }
};
</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 (%)"
    },
    "text": {
      "field": "name",
      "type": "nominal"
    },
    "textPriority": {
      "field": "rate",
      "type": "quantitative"
    }
  },
  "chrome": {
    "title": "Every state name that fits, placed highest rate first",
    "subtitle": "Unemployment rate by state (%); names come from the atlas"
  }
};

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

Names that do not fit are left off the map but stay in a visually hidden list tied to the map’s accessible description, so a screen reader can reach every name.

Point names

The points layer takes its own text channel, read from the point rows. Point labels need a unique points.key, and without a textPriority they place in order of symbol size, so the largest symbols keep their names first.

California and Texas lead the state economiesGDP of the ten largest state economies, 2023 ($ trillions)Map places and notes. point:CA: California. point CA. Visible on map. point:TX: Texas. point TX. Visible on map. point:NY: New York. point NY. Visible on map. point:FL: Florida. point FL. Visible on map. point:IL: Illinois. point IL. Visible on map. point:PA: Pennsylvania. point PA. Visible on map. point:OH: Ohio. point OH. Visible on map. point:GA: Georgia. point GA. Visible on map. point:NJ: New Jersey. point NJ. Visible on map. point:WA: Washington. point WA. Visible on map.California and Texas lead the state economiesGDP of the ten largest state economies, 2023 ($ trillions)Map places and notes. point:CA: California. point CA. Visible on map. point:TX: Texas. point TX. Visible on map. point:NY: New York. point NY. Visible on map. point:FL: Florida. point FL. Visible on map. point:IL: Illinois. point IL. Visible on map. point:PA: Pennsylvania. point PA. Visible on map. point:OH: Ohio. point OH. Visible on map. point:GA: Georgia. point GA. Visible on map. point:NJ: New Jersey. point NJ. Visible on map. point:WA: Washington. point WA. Visible on map.
The ten largest state economies, named. Source: Bureau of Economic Analysis, GDP by State; geography: US Census Bureau via us-atlas.
{
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 170 arcs; Copy includes it */},
    "projection": "albersUsa"
  },
  "data": [],
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    }
  },
  "points": {
    "data": [
      {
        "state": "California",
        "label": "CA",
        "gdp": 3.9,
        "pop": 39,
        "lon": -119.5,
        "lat": 37.23
      },
      {
        "state": "Texas",
        "label": "TX",
        "gdp": 2.6,
        "pop": 30.5,
        "lon": -99.28,
        "lat": 31.47
      },
      {
        "state": "New York",
        "label": "NY",
        "gdp": 2.1,
        "pop": 19.6,
        "lon": -75.53,
        "lat": 42.97
      },
      {
        "state": "Florida",
        "label": "FL",
        "gdp": 1.6,
        "pop": 22.6,
        "lon": -82.5,
        "lat": 28.67
      },
      {
        "state": "Illinois",
        "label": "IL",
        "gdp": 1.1,
        "pop": 12.5,
        "lon": -89.21,
        "lat": 40.02
      },
      {
        "state": "Pennsylvania",
        "label": "PA",
        "gdp": 1,
        "pop": 12.9,
        "lon": -77.78,
        "lat": 40.89
      },
      {
        "state": "Ohio",
        "label": "OH",
        "gdp": 0.9,
        "pop": 11.8,
        "lon": -82.78,
        "lat": 40.28
      },
      {
        "state": "Georgia",
        "label": "GA",
        "gdp": 0.8,
        "pop": 11,
        "lon": -83.4,
        "lat": 32.57
      },
      {
        "state": "New Jersey",
        "label": "NJ",
        "gdp": 0.8,
        "pop": 9.3,
        "lon": -74.64,
        "lat": 40.2
      },
      {
        "state": "Washington",
        "label": "WA",
        "gdp": 0.8,
        "pop": 7.8,
        "lon": -120.41,
        "lat": 47.36
      }
    ],
    "longitude": {
      "field": "lon",
      "type": "quantitative"
    },
    "latitude": {
      "field": "lat",
      "type": "quantitative"
    },
    "size": {
      "field": "gdp",
      "type": "quantitative",
      "title": "GDP ($ trillions)"
    },
    "key": {
      "field": "label",
      "type": "nominal"
    },
    "text": {
      "field": "state",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "California and Texas lead the state economies",
    "subtitle": "GDP of the ten largest state economies, 2023 ($ trillions)"
  }
}
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, 170 arcs; Copy includes it */},
    "projection": "albersUsa"
  },
  "data": [],
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    }
  },
  "points": {
    "data": [/* 10 rows, as in the Spec tab; Copy includes them */],
    "longitude": {
      "field": "lon",
      "type": "quantitative"
    },
    "latitude": {
      "field": "lat",
      "type": "quantitative"
    },
    "size": {
      "field": "gdp",
      "type": "quantitative",
      "title": "GDP ($ trillions)"
    },
    "key": {
      "field": "label",
      "type": "nominal"
    },
    "text": {
      "field": "state",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "California and Texas lead the state economies",
    "subtitle": "GDP of the ten largest state economies, 2023 ($ trillions)"
  }
};

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, 170 arcs; Copy includes it */},
    "projection": "albersUsa"
  },
  "data": [],
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    }
  },
  "points": {
    "data": [/* 10 rows, as in the Spec tab; Copy includes them */],
    "longitude": {
      "field": "lon",
      "type": "quantitative"
    },
    "latitude": {
      "field": "lat",
      "type": "quantitative"
    },
    "size": {
      "field": "gdp",
      "type": "quantitative",
      "title": "GDP ($ trillions)"
    },
    "key": {
      "field": "label",
      "type": "nominal"
    },
    "text": {
      "field": "state",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "California and Texas lead the state economies",
    "subtitle": "GDP of the ten largest state economies, 2023 ($ trillions)"
  }
};
</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, 170 arcs; Copy includes it */},
    "projection": "albersUsa"
  },
  "data": [],
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    }
  },
  "points": {
    "data": [/* 10 rows, as in the Spec tab; Copy includes them */],
    "longitude": {
      "field": "lon",
      "type": "quantitative"
    },
    "latitude": {
      "field": "lat",
      "type": "quantitative"
    },
    "size": {
      "field": "gdp",
      "type": "quantitative",
      "title": "GDP ($ trillions)"
    },
    "key": {
      "field": "label",
      "type": "nominal"
    },
    "text": {
      "field": "state",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "California and Texas lead the state economies",
    "subtitle": "GDP of the ten largest state economies, 2023 ($ trillions)"
  }
};
</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, 170 arcs; Copy includes it */},
    "projection": "albersUsa"
  },
  "data": [],
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    }
  },
  "points": {
    "data": [/* 10 rows, as in the Spec tab; Copy includes them */],
    "longitude": {
      "field": "lon",
      "type": "quantitative"
    },
    "latitude": {
      "field": "lat",
      "type": "quantitative"
    },
    "size": {
      "field": "gdp",
      "type": "quantitative",
      "title": "GDP ($ trillions)"
    },
    "key": {
      "field": "label",
      "type": "nominal"
    },
    "text": {
      "field": "state",
      "type": "nominal"
    }
  },
  "chrome": {
    "title": "California and Texas lead the state economies",
    "subtitle": "GDP of the ten largest state economies, 2023 ($ trillions)"
  }
};

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

Callouts

callouts adds written notes, each with a unique id, an anchor and text, plus an optional subtitle, priority and maxWidth. An anchor is a feature ({ kind: "feature", id }), a point by its key, or a longitude and latitude. Callouts place before region and point names. A callout that does not fit moves to a numbered note, with a marker on its anchor when there is room.

minZoom holds a callout back until the reader zooms in that far, and geo.zoom: true lets them: hold Ctrl or Command and scroll, pinch, or double-click.

Unemployment runs from 2.3% to 5.7%Unemployment rate by state (%); zoom in on New England for one more note3.04.05.0Unemployment rate (%)Map places and notes. callout:highest: DC: 5.7%. feature 11. Visible on map. callout:lowest: South Dakota: 2.3%. feature 46. Visible on map. callout:rhode-island: Rhode Island: 4.9%. feature 44. Visible at another zoom level.Unemployment runs from 2.3% to 5.7%Unemployment rate by state (%); zoom in on New England for one more note3.04.05.0Unemployment rate (%)Map places and notes. callout:highest: DC: 5.7%. feature 11. Visible on map. callout:lowest: South Dakota: 2.3%. feature 46. Visible on map. callout:rhode-island: Rhode Island: 4.9%. feature 44. Visible at another zoom level.
Callouts on the highest and lowest rates. 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",
    "zoom": true
  },
  "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 (%)"
    }
  },
  "callouts": [
    {
      "id": "highest",
      "anchor": {
        "kind": "feature",
        "id": "11"
      },
      "text": "DC: 5.7%",
      "priority": 10
    },
    {
      "id": "lowest",
      "anchor": {
        "kind": "feature",
        "id": "46"
      },
      "text": "South Dakota: 2.3%",
      "priority": 9
    },
    {
      "id": "rhode-island",
      "anchor": {
        "kind": "feature",
        "id": "44"
      },
      "text": "Rhode Island: 4.9%",
      "minZoom": 3,
      "maxWidth": 160
    }
  ],
  "chrome": {
    "title": "Unemployment runs from 2.3% to 5.7%",
    "subtitle": "Unemployment rate by state (%); zoom in on New England for one more note"
  }
}
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",
    "zoom": true
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "rate",
      "type": "quantitative",
      "format": ".1f",
      "title": "Unemployment rate (%)"
    }
  },
  "callouts": [
    {
      "id": "highest",
      "anchor": {
        "kind": "feature",
        "id": "11"
      },
      "text": "DC: 5.7%",
      "priority": 10
    },
    {
      "id": "lowest",
      "anchor": {
        "kind": "feature",
        "id": "46"
      },
      "text": "South Dakota: 2.3%",
      "priority": 9
    },
    {
      "id": "rhode-island",
      "anchor": {
        "kind": "feature",
        "id": "44"
      },
      "text": "Rhode Island: 4.9%",
      "minZoom": 3,
      "maxWidth": 160
    }
  ],
  "chrome": {
    "title": "Unemployment runs from 2.3% to 5.7%",
    "subtitle": "Unemployment rate by state (%); zoom in on New England for one more note"
  }
};

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",
    "zoom": true
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "rate",
      "type": "quantitative",
      "format": ".1f",
      "title": "Unemployment rate (%)"
    }
  },
  "callouts": [
    {
      "id": "highest",
      "anchor": {
        "kind": "feature",
        "id": "11"
      },
      "text": "DC: 5.7%",
      "priority": 10
    },
    {
      "id": "lowest",
      "anchor": {
        "kind": "feature",
        "id": "46"
      },
      "text": "South Dakota: 2.3%",
      "priority": 9
    },
    {
      "id": "rhode-island",
      "anchor": {
        "kind": "feature",
        "id": "44"
      },
      "text": "Rhode Island: 4.9%",
      "minZoom": 3,
      "maxWidth": 160
    }
  ],
  "chrome": {
    "title": "Unemployment runs from 2.3% to 5.7%",
    "subtitle": "Unemployment rate by state (%); zoom in on New England for one more note"
  }
};
</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",
    "zoom": true
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "rate",
      "type": "quantitative",
      "format": ".1f",
      "title": "Unemployment rate (%)"
    }
  },
  "callouts": [
    {
      "id": "highest",
      "anchor": {
        "kind": "feature",
        "id": "11"
      },
      "text": "DC: 5.7%",
      "priority": 10
    },
    {
      "id": "lowest",
      "anchor": {
        "kind": "feature",
        "id": "46"
      },
      "text": "South Dakota: 2.3%",
      "priority": 9
    },
    {
      "id": "rhode-island",
      "anchor": {
        "kind": "feature",
        "id": "44"
      },
      "text": "Rhode Island: 4.9%",
      "minZoom": 3,
      "maxWidth": 160
    }
  ],
  "chrome": {
    "title": "Unemployment runs from 2.3% to 5.7%",
    "subtitle": "Unemployment rate by state (%); zoom in on New England for one more note"
  }
};
</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",
    "zoom": true
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "rate",
      "type": "quantitative",
      "format": ".1f",
      "title": "Unemployment rate (%)"
    }
  },
  "callouts": [
    {
      "id": "highest",
      "anchor": {
        "kind": "feature",
        "id": "11"
      },
      "text": "DC: 5.7%",
      "priority": 10
    },
    {
      "id": "lowest",
      "anchor": {
        "kind": "feature",
        "id": "46"
      },
      "text": "South Dakota: 2.3%",
      "priority": 9
    },
    {
      "id": "rhode-island",
      "anchor": {
        "kind": "feature",
        "id": "44"
      },
      "text": "Rhode Island: 4.9%",
      "minZoom": 3,
      "maxWidth": 160
    }
  ],
  "chrome": {
    "title": "Unemployment runs from 2.3% to 5.7%",
    "subtitle": "Unemployment rate by state (%); zoom in on New England for one more note"
  }
};

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

The labels keep their screen size while the map zooms and pans, and settle into place when the camera stops.

Fields that matter

Field What it does
encoding.text The field that names each region, from its row or its topology properties.
encoding.textPriority A number; higher values win when region labels collide.
points.text The field that names each point. Needs a unique points.key.
callouts Authored notes with an id, an anchor and text.
callouts[].anchor A feature, a point, or a coordinate the note points at.
callouts[].minZoom The zoom level a note waits for; 1 is the full map.
geo.zoom Lets readers zoom and pan. Off by default.