Facets and small multiples
Repeat one chart as a grid of panels, one per category, with shared or independent scales and wrapped, row or column layouts.
Faceting repeats one chart as a grid of panels, one panel per value of a field. It is the better choice when several series overlap too much to read in one plot, or when the point is to compare shapes across groups.
When the series are few and do not overlap, one line chart with a line per series keeps them in one view. When two marks belong in the same plot, use layers.
A wrapped grid
encoding.facet wraps panels left to right. columns sets the grid width, and it is computed when omitted. Scales are shared by default, so panels are directly comparable, and redundant tick labels are stripped: y-axis labels show only on the leftmost column.
{
"mark": "line",
"data": [
{
"date": "2018-01-01",
"gdp": 3,
"country": "United States"
},
{
"date": "2019-01-01",
"gdp": 2.5,
"country": "United States"
},
{
"date": "2020-01-01",
"gdp": -2.2,
"country": "United States"
},
{
"date": "2021-01-01",
"gdp": 6.1,
"country": "United States"
},
{
"date": "2022-01-01",
"gdp": 2.5,
"country": "United States"
},
{
"date": "2023-01-01",
"gdp": 2.9,
"country": "United States"
},
// … 15 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "gdp",
"type": "quantitative",
"axis": {
"format": ".0f"
}
},
"facet": {
"field": "country",
"type": "nominal",
"columns": 3
}
},
"chrome": {
"title": "One panel per economy, one shared scale",
"subtitle": "Annual real GDP growth split into a small-multiples grid by country (shared y-axis)"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 21 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "line",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "gdp",
"type": "quantitative",
"axis": {
"format": ".0f"
}
},
"facet": {
"field": "country",
"type": "nominal",
"columns": 3
}
},
"chrome": {
"title": "One panel per economy, one shared scale",
"subtitle": "Annual real GDP growth split into a small-multiples grid by country (shared y-axis)"
}
};
export function Example() {
return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 21 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "line",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "gdp",
"type": "quantitative",
"axis": {
"format": ".0f"
}
},
"facet": {
"field": "country",
"type": "nominal",
"columns": 3
}
},
"chrome": {
"title": "One panel per economy, one shared scale",
"subtitle": "Annual real GDP growth split into a small-multiples grid by country (shared y-axis)"
}
};
</script>
<template>
<Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 21 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "line",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "gdp",
"type": "quantitative",
"axis": {
"format": ".0f"
}
},
"facet": {
"field": "country",
"type": "nominal",
"columns": 3
}
},
"chrome": {
"title": "One panel per economy, one shared scale",
"subtitle": "Annual real GDP growth split into a small-multiples grid by country (shared y-axis)"
}
};
</script>
<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 21 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "line",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "gdp",
"type": "quantitative",
"axis": {
"format": ".0f"
}
},
"facet": {
"field": "country",
"type": "nominal",
"columns": 3
}
},
"chrome": {
"title": "One panel per economy, one shared scale",
"subtitle": "Annual real GDP growth split into a small-multiples grid by country (shared y-axis)"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
Independent scales
resolve: { scale: { y: "independent" } } gives each panel its own y domain. Each economy then fills its frame, so the shape reads and the level does not. Use it to compare the shape of each series, and keep shared scales to compare levels.
{
"mark": "line",
"data": [
{
"date": "2018-01-01",
"gdp": 3,
"country": "United States"
},
{
"date": "2019-01-01",
"gdp": 2.5,
"country": "United States"
},
{
"date": "2020-01-01",
"gdp": -2.2,
"country": "United States"
},
{
"date": "2021-01-01",
"gdp": 6.1,
"country": "United States"
},
{
"date": "2022-01-01",
"gdp": 2.5,
"country": "United States"
},
{
"date": "2023-01-01",
"gdp": 2.9,
"country": "United States"
},
// … 15 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "gdp",
"type": "quantitative",
"axis": {
"format": ".0f"
}
},
"facet": {
"field": "country",
"type": "nominal",
"columns": 3
}
},
"resolve": {
"scale": {
"y": "independent"
}
},
"chrome": {
"title": "Independent y-scales show each economy's swings at full height",
"subtitle": "Each panel gets its own y-domain, so each economy fills its frame"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 21 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "line",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "gdp",
"type": "quantitative",
"axis": {
"format": ".0f"
}
},
"facet": {
"field": "country",
"type": "nominal",
"columns": 3
}
},
"resolve": {
"scale": {
"y": "independent"
}
},
"chrome": {
"title": "Independent y-scales show each economy's swings at full height",
"subtitle": "Each panel gets its own y-domain, so each economy fills its frame"
}
};
export function Example() {
return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 21 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "line",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "gdp",
"type": "quantitative",
"axis": {
"format": ".0f"
}
},
"facet": {
"field": "country",
"type": "nominal",
"columns": 3
}
},
"resolve": {
"scale": {
"y": "independent"
}
},
"chrome": {
"title": "Independent y-scales show each economy's swings at full height",
"subtitle": "Each panel gets its own y-domain, so each economy fills its frame"
}
};
</script>
<template>
<Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 21 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "line",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "gdp",
"type": "quantitative",
"axis": {
"format": ".0f"
}
},
"facet": {
"field": "country",
"type": "nominal",
"columns": 3
}
},
"resolve": {
"scale": {
"y": "independent"
}
},
"chrome": {
"title": "Independent y-scales show each economy's swings at full height",
"subtitle": "Each panel gets its own y-domain, so each economy fills its frame"
}
};
</script>
<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 21 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "line",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "gdp",
"type": "quantitative",
"axis": {
"format": ".0f"
}
},
"facet": {
"field": "country",
"type": "nominal",
"columns": 3
}
},
"resolve": {
"scale": {
"y": "independent"
}
},
"chrome": {
"title": "Independent y-scales show each economy's swings at full height",
"subtitle": "Each panel gets its own y-domain, so each economy fills its frame"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
Panels in a single row
encoding.column places the panels side by side in one row. The y axis is shared by default and each panel gets its own x axis. Each panel has a 200px minimum width, and the columns degrade responsively below that.
{
"mark": "line",
"data": [
{
"date": "2018-01-01",
"gdp": 3,
"country": "United States"
},
{
"date": "2019-01-01",
"gdp": 2.5,
"country": "United States"
},
{
"date": "2020-01-01",
"gdp": -2.2,
"country": "United States"
},
{
"date": "2021-01-01",
"gdp": 6.1,
"country": "United States"
},
{
"date": "2022-01-01",
"gdp": 2.5,
"country": "United States"
},
{
"date": "2023-01-01",
"gdp": 2.9,
"country": "United States"
},
// … 15 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "gdp",
"type": "quantitative",
"axis": {
"format": ".0f"
}
},
"column": {
"field": "country",
"type": "nominal"
}
},
"chrome": {
"title": "The same three economies in one row",
"subtitle": "Annual real GDP growth, one column per country"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 21 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "line",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "gdp",
"type": "quantitative",
"axis": {
"format": ".0f"
}
},
"column": {
"field": "country",
"type": "nominal"
}
},
"chrome": {
"title": "The same three economies in one row",
"subtitle": "Annual real GDP growth, one column per country"
}
};
export function Example() {
return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 21 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "line",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "gdp",
"type": "quantitative",
"axis": {
"format": ".0f"
}
},
"column": {
"field": "country",
"type": "nominal"
}
},
"chrome": {
"title": "The same three economies in one row",
"subtitle": "Annual real GDP growth, one column per country"
}
};
</script>
<template>
<Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 21 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "line",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "gdp",
"type": "quantitative",
"axis": {
"format": ".0f"
}
},
"column": {
"field": "country",
"type": "nominal"
}
},
"chrome": {
"title": "The same three economies in one row",
"subtitle": "Annual real GDP growth, one column per country"
}
};
</script>
<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 21 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "line",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "gdp",
"type": "quantitative",
"axis": {
"format": ".0f"
}
},
"column": {
"field": "country",
"type": "nominal"
}
},
"chrome": {
"title": "The same three economies in one row",
"subtitle": "Annual real GDP growth, one column per country"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
Panels in a single column
encoding.row stacks the panels vertically. It shares the x axis by default, so bar lengths line up between panels, and each panel gets its own y axis because the categories differ. sort: null keeps the panel order as it appears in the data.
{
"mark": {
"type": "bar",
"orient": "horizontal"
},
"data": [
{
"period": "2011-12",
"state": "Oregon",
"rate": 6.4,
"party": "Blue"
},
{
"period": "2011-12",
"state": "Washington",
"rate": 5.2,
"party": "Blue"
},
{
"period": "2011-12",
"state": "Vermont",
"rate": 4.8,
"party": "Blue"
},
{
"period": "2011-12",
"state": "Colorado",
"rate": 4.1,
"party": "Blue"
},
{
"period": "2024-25",
"state": "Idaho",
"rate": 8.1,
"party": "Red"
},
{
"period": "2024-25",
"state": "Wyoming",
"rate": 7.3,
"party": "Red"
},
{
"period": "2024-25",
"state": "Alaska",
"rate": 6.9,
"party": "Red"
},
{
"period": "2024-25",
"state": "Utah",
"rate": 5.8,
"party": "Red"
}
],
"encoding": {
"x": {
"field": "rate",
"type": "quantitative",
"axis": {
"title": "Exemption rate (%)"
}
},
"y": {
"field": "state",
"type": "nominal",
"sort": null
},
"color": {
"field": "party",
"type": "nominal",
"scale": {
"range": [
"#4373b8",
"#d1495b"
]
}
},
"row": {
"field": "period",
"type": "ordinal",
"sort": null
}
},
"chrome": {
"title": "The highest exemption rates moved from blue states to red states",
"subtitle": "Exemption rate in the four highest states, 2011-12 and 2024-25 (%)"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "bar",
"orient": "horizontal"
},
"encoding": {
"x": {
"field": "rate",
"type": "quantitative",
"axis": {
"title": "Exemption rate (%)"
}
},
"y": {
"field": "state",
"type": "nominal",
"sort": null
},
"color": {
"field": "party",
"type": "nominal",
"scale": {
"range": [
"#4373b8",
"#d1495b"
]
}
},
"row": {
"field": "period",
"type": "ordinal",
"sort": null
}
},
"chrome": {
"title": "The highest exemption rates moved from blue states to red states",
"subtitle": "Exemption rate in the four highest states, 2011-12 and 2024-25 (%)"
}
};
export function Example() {
return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "bar",
"orient": "horizontal"
},
"encoding": {
"x": {
"field": "rate",
"type": "quantitative",
"axis": {
"title": "Exemption rate (%)"
}
},
"y": {
"field": "state",
"type": "nominal",
"sort": null
},
"color": {
"field": "party",
"type": "nominal",
"scale": {
"range": [
"#4373b8",
"#d1495b"
]
}
},
"row": {
"field": "period",
"type": "ordinal",
"sort": null
}
},
"chrome": {
"title": "The highest exemption rates moved from blue states to red states",
"subtitle": "Exemption rate in the four highest states, 2011-12 and 2024-25 (%)"
}
};
</script>
<template>
<Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "bar",
"orient": "horizontal"
},
"encoding": {
"x": {
"field": "rate",
"type": "quantitative",
"axis": {
"title": "Exemption rate (%)"
}
},
"y": {
"field": "state",
"type": "nominal",
"sort": null
},
"color": {
"field": "party",
"type": "nominal",
"scale": {
"range": [
"#4373b8",
"#d1495b"
]
}
},
"row": {
"field": "period",
"type": "ordinal",
"sort": null
}
},
"chrome": {
"title": "The highest exemption rates moved from blue states to red states",
"subtitle": "Exemption rate in the four highest states, 2011-12 and 2024-25 (%)"
}
};
</script>
<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "bar",
"orient": "horizontal"
},
"encoding": {
"x": {
"field": "rate",
"type": "quantitative",
"axis": {
"title": "Exemption rate (%)"
}
},
"y": {
"field": "state",
"type": "nominal",
"sort": null
},
"color": {
"field": "party",
"type": "nominal",
"scale": {
"range": [
"#4373b8",
"#d1495b"
]
}
},
"row": {
"field": "period",
"type": "ordinal",
"sort": null
}
},
"chrome": {
"title": "The highest exemption rates moved from blue states to red states",
"subtitle": "Exemption rate in the four highest states, 2011-12 and 2024-25 (%)"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
Fields that matter
| Field | What it does |
|---|---|
encoding.facet |
A wrapped grid of panels. Takes field, type, sort and columns. |
encoding.row |
Panels stacked vertically, one per value. |
encoding.column |
Panels side by side in one row. |
resolve.scale |
"shared" or "independent" per channel, such as y. The default is shared. |
sort |
On a facet channel, orders the panels. null keeps the data order. |
The three facet channels are mutually exclusive: row and column cannot be combined, and neither can be combined with facet.
Related
- Layers for several marks in one plot.
- Line for a few series in one plot.
- Bar for the chart used in the row layout.
- Encoding reference lists the faceting fields along with every channel.