Tile map
Give every US state one equal tile in a grid that keeps the country's rough shape, colored by a number or a category.
A tile map gives each US state the same square in a grid that keeps the country’s rough shape. Small states such as Rhode Island and Delaware get as much room as Texas, so every value is readable and none dominates by area. It needs no geography file and no projection.
Use a choropleth when real borders and shapes matter, such as for neighboring counties, and a bar chart when the reader needs the states in rank order.
A basic tile map
Set type to "tilemap" and pass data as a record of two-letter state codes to numbers. That is all the spec needs: the color scale and legend come from the values. palette picks one of five sequential palettes ("blue", the default, "green", "orange", "purple" and "teal"), and valueFormat takes a d3-format string for the tile labels, legend and tooltips.
{
"type": "tilemap",
"data": {
"AL": 2.7,
"AK": 4.8,
"AZ": 4.7,
"AR": 4.2,
"CA": 5.3,
"CO": 3.8,
"CT": 4.8,
"DE": 5.4,
"DC": 5.7,
"FL": 4.4,
"GA": 3.5,
"HI": 2.4,
"ID": 3.6,
"IL": 5.1,
"IN": 3.6,
"IA": 3.3,
"KS": 3.8,
"KY": 4.2,
"LA": 4.4,
"ME": 3.3,
"MD": 4.3,
"MA": 4.7,
"MI": 5.1,
"MN": 4.9,
"MS": 3.8,
"MO": 4.2,
"MT": 3.6,
"NE": 3.1,
"NV": 5.1,
"NH": 3,
"NJ": 4.9,
"NM": 4.8,
"NY": 4.4,
"NC": 3.7,
"ND": 2.8,
"OH": 4,
"OK": 3.9,
"OR": 5.2,
"PA": 4.2,
"RI": 4.9,
"SC": 4.2,
"SD": 2.3,
"TN": 3.3,
"TX": 4.3,
"UT": 3.8,
"VT": 2.6,
"VA": 3.8,
"WA": 5.1,
"WV": 4.5,
"WI": 4,
"WY": 3.8
},
"palette": "blue",
"valueFormat": ".1f",
"chrome": {
"title": "Unemployment is highest in DC and lowest in South Dakota",
"subtitle": "State unemployment rate, seasonally adjusted (%)"
}
}import { TileMap } from "@opendata-ai/openchart-react";
import type { TileMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const spec: TileMapSpec = {
"type": "tilemap",
"data": {/* 51 entries, as in the Spec tab; Copy includes them */},
"palette": "blue",
"valueFormat": ".1f",
"chrome": {
"title": "Unemployment is highest in DC and lowest in South Dakota",
"subtitle": "State unemployment rate, seasonally adjusted (%)"
}
};
export function Example() {
return <TileMap spec={spec} />;
}
<script setup lang="ts">
import { TileMap } from "@opendata-ai/openchart-vue";
import type { TileMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const spec: TileMapSpec = {
"type": "tilemap",
"data": {/* 51 entries, as in the Spec tab; Copy includes them */},
"palette": "blue",
"valueFormat": ".1f",
"chrome": {
"title": "Unemployment is highest in DC and lowest in South Dakota",
"subtitle": "State unemployment rate, seasonally adjusted (%)"
}
};
</script>
<template>
<TileMap :spec="spec" />
</template>
<script lang="ts">
import { TileMap } from "@opendata-ai/openchart-svelte";
import type { TileMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const spec: TileMapSpec = {
"type": "tilemap",
"data": {/* 51 entries, as in the Spec tab; Copy includes them */},
"palette": "blue",
"valueFormat": ".1f",
"chrome": {
"title": "Unemployment is highest in DC and lowest in South Dakota",
"subtitle": "State unemployment rate, seasonally adjusted (%)"
}
};
</script>
<TileMap {spec} />
import { createTileMap } from "@opendata-ai/openchart-vanilla";
import type { TileMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const spec: TileMapSpec = {
"type": "tilemap",
"data": {/* 51 entries, as in the Spec tab; Copy includes them */},
"palette": "blue",
"valueFormat": ".1f",
"chrome": {
"title": "Unemployment is highest in DC and lowest in South Dakota",
"subtitle": "State unemployment rate, seasonally adjusted (%)"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createTileMap(container, spec);
Each tile shows the state code and its value. The label color is worked out against the tile’s color as drawn, so pale tiles get dark text and deep tiles get light text.
Categories
When the values are strings, the map colors by category, and colors assigns a color to each one. A colors record makes the map categorical whatever the values are. The legend lists the categories instead of a color ramp.
{
"type": "tilemap",
"data": {
"AL": "Religious",
"AK": "Religious",
"AZ": "Philosophical",
"AR": "Philosophical",
"CA": "Medical only",
"CO": "Philosophical",
"CT": "Religious",
"DE": "Religious",
"DC": "Religious",
"FL": "Religious",
"GA": "Religious",
"HI": "Religious",
"ID": "Philosophical",
"IL": "Religious",
"IN": "Religious",
"IA": "Religious",
"KS": "Religious",
"KY": "Religious",
"LA": "Philosophical",
"ME": "Philosophical",
"MD": "Religious",
"MA": "Religious",
"MI": "Philosophical",
"MN": "Philosophical",
"MS": "Medical only",
"MO": "Religious",
"MT": "Religious",
"NE": "Religious",
"NV": "Religious",
"NH": "Religious",
"NJ": "Religious",
"NM": "Religious",
"NY": "Medical only",
"NC": "Religious",
"ND": "Philosophical",
"OH": "Philosophical",
"OK": "Philosophical",
"OR": "Philosophical",
"PA": "Philosophical",
"RI": "Religious",
"SC": "Religious",
"SD": "Religious",
"TN": "Religious",
"TX": "Philosophical",
"UT": "Philosophical",
"VT": "Religious",
"VA": "Religious",
"WA": "Philosophical",
"WV": "Medical only",
"WI": "Philosophical",
"WY": "Religious"
},
"colors": {
"Medical only": "#ee4a73",
"Religious": "#e07d00",
"Philosophical": "#06b6d4"
},
"chrome": {
"title": "Broadest vaccine exemption each state allows",
"subtitle": "Medical only, religious, or philosophical"
}
}import { TileMap } from "@opendata-ai/openchart-react";
import type { TileMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const spec: TileMapSpec = {
"type": "tilemap",
"data": {/* 51 entries, as in the Spec tab; Copy includes them */},
"colors": {
"Medical only": "#ee4a73",
"Religious": "#e07d00",
"Philosophical": "#06b6d4"
},
"chrome": {
"title": "Broadest vaccine exemption each state allows",
"subtitle": "Medical only, religious, or philosophical"
}
};
export function Example() {
return <TileMap spec={spec} />;
}
<script setup lang="ts">
import { TileMap } from "@opendata-ai/openchart-vue";
import type { TileMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const spec: TileMapSpec = {
"type": "tilemap",
"data": {/* 51 entries, as in the Spec tab; Copy includes them */},
"colors": {
"Medical only": "#ee4a73",
"Religious": "#e07d00",
"Philosophical": "#06b6d4"
},
"chrome": {
"title": "Broadest vaccine exemption each state allows",
"subtitle": "Medical only, religious, or philosophical"
}
};
</script>
<template>
<TileMap :spec="spec" />
</template>
<script lang="ts">
import { TileMap } from "@opendata-ai/openchart-svelte";
import type { TileMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const spec: TileMapSpec = {
"type": "tilemap",
"data": {/* 51 entries, as in the Spec tab; Copy includes them */},
"colors": {
"Medical only": "#ee4a73",
"Religious": "#e07d00",
"Philosophical": "#06b6d4"
},
"chrome": {
"title": "Broadest vaccine exemption each state allows",
"subtitle": "Medical only, religious, or philosophical"
}
};
</script>
<TileMap {spec} />
import { createTileMap } from "@opendata-ai/openchart-vanilla";
import type { TileMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const spec: TileMapSpec = {
"type": "tilemap",
"data": {/* 51 entries, as in the Spec tab; Copy includes them */},
"colors": {
"Medical only": "#ee4a73",
"Religious": "#e07d00",
"Philosophical": "#06b6d4"
},
"chrome": {
"title": "Broadest vaccine exemption each state allows",
"subtitle": "Medical only, religious, or philosophical"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createTileMap(container, spec);
Rows and missing states
data can also be rows, like any other spec, with an encoding that names the state field (two-letter codes) and the value field. With an encoding, the number format goes on encoding.value.format; the library warns that valueFormat is deprecated there. States without a row keep their place in the grid as empty outlined tiles, so the shape of the map never changes, and the legend adds a “No data” swatch.
{
"type": "tilemap",
"data": [
{
"state": "California",
"label": "CA",
"gdp": 3.9,
"pop": 39
},
{
"state": "Texas",
"label": "TX",
"gdp": 2.6,
"pop": 30.5
},
{
"state": "New York",
"label": "NY",
"gdp": 2.1,
"pop": 19.6
},
{
"state": "Florida",
"label": "FL",
"gdp": 1.6,
"pop": 22.6
},
{
"state": "Illinois",
"label": "IL",
"gdp": 1.1,
"pop": 12.5
},
{
"state": "Pennsylvania",
"label": "PA",
"gdp": 1,
"pop": 12.9
},
{
"state": "Ohio",
"label": "OH",
"gdp": 0.9,
"pop": 11.8
},
{
"state": "Georgia",
"label": "GA",
"gdp": 0.8,
"pop": 11
},
{
"state": "New Jersey",
"label": "NJ",
"gdp": 0.8,
"pop": 9.3
},
{
"state": "Washington",
"label": "WA",
"gdp": 0.8,
"pop": 7.8
}
],
"encoding": {
"state": {
"field": "label",
"type": "nominal"
},
"value": {
"field": "gdp",
"type": "quantitative",
"format": ".1f"
}
},
"palette": "green",
"chrome": {
"title": "Ten states, the rest left blank",
"subtitle": "GDP of the ten largest state economies, 2023 ($ trillions)"
}
}import { TileMap } from "@opendata-ai/openchart-react";
import type { TileMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 10 rows, as in the Spec tab; Copy includes them */];
const spec: TileMapSpec = {
data,
"type": "tilemap",
"encoding": {
"state": {
"field": "label",
"type": "nominal"
},
"value": {
"field": "gdp",
"type": "quantitative",
"format": ".1f"
}
},
"palette": "green",
"chrome": {
"title": "Ten states, the rest left blank",
"subtitle": "GDP of the ten largest state economies, 2023 ($ trillions)"
}
};
export function Example() {
return <TileMap spec={spec} />;
}
<script setup lang="ts">
import { TileMap } from "@opendata-ai/openchart-vue";
import type { TileMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 10 rows, as in the Spec tab; Copy includes them */];
const spec: TileMapSpec = {
data,
"type": "tilemap",
"encoding": {
"state": {
"field": "label",
"type": "nominal"
},
"value": {
"field": "gdp",
"type": "quantitative",
"format": ".1f"
}
},
"palette": "green",
"chrome": {
"title": "Ten states, the rest left blank",
"subtitle": "GDP of the ten largest state economies, 2023 ($ trillions)"
}
};
</script>
<template>
<TileMap :spec="spec" />
</template>
<script lang="ts">
import { TileMap } from "@opendata-ai/openchart-svelte";
import type { TileMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 10 rows, as in the Spec tab; Copy includes them */];
const spec: TileMapSpec = {
data,
"type": "tilemap",
"encoding": {
"state": {
"field": "label",
"type": "nominal"
},
"value": {
"field": "gdp",
"type": "quantitative",
"format": ".1f"
}
},
"palette": "green",
"chrome": {
"title": "Ten states, the rest left blank",
"subtitle": "GDP of the ten largest state economies, 2023 ($ trillions)"
}
};
</script>
<TileMap {spec} />
import { createTileMap } from "@opendata-ai/openchart-vanilla";
import type { TileMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 10 rows, as in the Spec tab; Copy includes them */];
const spec: TileMapSpec = {
data,
"type": "tilemap",
"encoding": {
"state": {
"field": "label",
"type": "nominal"
},
"value": {
"field": "gdp",
"type": "quantitative",
"format": ".1f"
}
},
"palette": "green",
"chrome": {
"title": "Ten states, the rest left blank",
"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.');
createTileMap(container, spec);
Over time
With encoding.time, a tile map plays through periods and reshades each tile from one color scale fixed for the whole run. It needs rows with encoding.state and a quantitative encoding.value, and no categorical colors. The time-lapse map page shows it with 2020 unemployment data.
Fields that matter
| Field | What it does |
|---|---|
type |
"tilemap" selects this visualization. |
data |
A record of state code to value, or rows with an encoding. |
encoding.state, encoding.value |
With rows, the state code field and the value field; value.format formats the numbers. |
palette |
"blue", "green", "orange", "purple" or "teal" for numeric values. Default "blue". |
colors |
A record of category to color; makes the map categorical. |
valueFormat |
With a record, a d3-format string for tile labels, the legend and tooltips. |
Related
- Choropleth for real state shapes.
- Time-lapse map for a tile map played through periods.
- Bar for the same values in rank order.
- Data table for the values with their state names.
- TileMapSpec reference lists every tile map field.