Beeswarm
Draw every observation as a dot, dodged so none overlap, then split into lanes by group, turn the swarm vertical and size dots by a second field.
A beeswarm shows each observation as its own dot along one value axis, dodged apart so no two dots overlap. The pile-up along the axis becomes the shape of the distribution while every data point stays visible.
It is better than a histogram when you want every point visible, and better than a tick strip when the data is dense enough that ticks would pile up. When you only need the outline of the distribution, a density curve reads faster.
A basic beeswarm
Set mark to "beeswarm" and put the value on x. One positional channel carries the quantitative value, and the other is optional. With only x, all the dots share one lane.
{
"mark": "beeswarm",
"data": [
{
"region": "Northeast",
"income": 96.1,
"population": 171
},
{
"region": "Northeast",
"income": 86.6,
"population": 415
},
{
"region": "Northeast",
"income": 64.4,
"population": 21
},
{
"region": "Northeast",
"income": 83.8,
"population": 23
},
{
"region": "Northeast",
"income": 61,
"population": 97
},
{
"region": "Northeast",
"income": 58,
"population": 128
},
// … 42 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
}
},
"chrome": {
"title": "Incomes bunch in the middle and thin at the edges",
"subtitle": "Median household income by county. Each dot is one county."
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
}
},
"chrome": {
"title": "Incomes bunch in the middle and thin at the edges",
"subtitle": "Median household income by county. Each dot is one county."
}
};
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 = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
}
},
"chrome": {
"title": "Incomes bunch in the middle and thin at the edges",
"subtitle": "Median household income by county. Each dot is one county."
}
};
</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 = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
}
},
"chrome": {
"title": "Incomes bunch in the middle and thin at the edges",
"subtitle": "Median household income by county. Each dot is one county."
}
};
</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 = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
}
},
"chrome": {
"title": "Incomes bunch in the middle and thin at the edges",
"subtitle": "Median household income by county. Each dot is one county."
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
Lanes by group
Add a nominal y to split the swarm into one lane per category, and a color channel to tell the lanes apart. The legend is redundant here because the lanes are already labeled, so legend: { show: false } removes it.
{
"mark": "beeswarm",
"data": [
{
"region": "Northeast",
"income": 96.1,
"population": 171
},
{
"region": "Northeast",
"income": 86.6,
"population": 415
},
{
"region": "Northeast",
"income": 64.4,
"population": 21
},
{
"region": "Northeast",
"income": 83.8,
"population": 23
},
{
"region": "Northeast",
"income": 61,
"population": 97
},
{
"region": "Northeast",
"income": 58,
"population": 128
},
// … 42 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
},
"y": {
"field": "region",
"type": "nominal"
},
"color": {
"field": "region",
"type": "nominal"
}
},
"legend": {
"show": false
},
"chrome": {
"title": "Northeast and West counties have the highest median incomes",
"subtitle": "Median household income by county, grouped by region"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
},
"y": {
"field": "region",
"type": "nominal"
},
"color": {
"field": "region",
"type": "nominal"
}
},
"legend": {
"show": false
},
"chrome": {
"title": "Northeast and West counties have the highest median incomes",
"subtitle": "Median household income by county, grouped by region"
}
};
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 = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
},
"y": {
"field": "region",
"type": "nominal"
},
"color": {
"field": "region",
"type": "nominal"
}
},
"legend": {
"show": false
},
"chrome": {
"title": "Northeast and West counties have the highest median incomes",
"subtitle": "Median household income by county, grouped by region"
}
};
</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 = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
},
"y": {
"field": "region",
"type": "nominal"
},
"color": {
"field": "region",
"type": "nominal"
}
},
"legend": {
"show": false
},
"chrome": {
"title": "Northeast and West counties have the highest median incomes",
"subtitle": "Median household income by county, grouped by region"
}
};
</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 = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
},
"y": {
"field": "region",
"type": "nominal"
},
"color": {
"field": "region",
"type": "nominal"
}
},
"legend": {
"show": false
},
"chrome": {
"title": "Northeast and West counties have the highest median incomes",
"subtitle": "Median household income by county, grouped by region"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
Vertical swarms
Swap the channels to turn the swarm: y holds the quantitative value and x holds the category.
{
"mark": "beeswarm",
"data": [
{
"region": "Northeast",
"income": 96.1,
"population": 171
},
{
"region": "Northeast",
"income": 86.6,
"population": 415
},
{
"region": "Northeast",
"income": 64.4,
"population": 21
},
{
"region": "Northeast",
"income": 83.8,
"population": 23
},
{
"region": "Northeast",
"income": 61,
"population": 97
},
{
"region": "Northeast",
"income": 58,
"population": 128
},
// … 42 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "region",
"type": "nominal"
},
"y": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
},
"color": {
"field": "region",
"type": "nominal"
}
},
"legend": {
"show": false
},
"chrome": {
"title": "The same swarms on a vertical value axis",
"subtitle": "Median household income by county, grouped by region"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "region",
"type": "nominal"
},
"y": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
},
"color": {
"field": "region",
"type": "nominal"
}
},
"legend": {
"show": false
},
"chrome": {
"title": "The same swarms on a vertical value axis",
"subtitle": "Median household income by county, grouped by region"
}
};
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 = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "region",
"type": "nominal"
},
"y": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
},
"color": {
"field": "region",
"type": "nominal"
}
},
"legend": {
"show": false
},
"chrome": {
"title": "The same swarms on a vertical value axis",
"subtitle": "Median household income by county, grouped by region"
}
};
</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 = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "region",
"type": "nominal"
},
"y": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
},
"color": {
"field": "region",
"type": "nominal"
}
},
"legend": {
"show": false
},
"chrome": {
"title": "The same swarms on a vertical value axis",
"subtitle": "Median household income by county, grouped by region"
}
};
</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 = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "region",
"type": "nominal"
},
"y": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
},
"color": {
"field": "region",
"type": "nominal"
}
},
"legend": {
"show": false
},
"chrome": {
"title": "The same swarms on a vertical value axis",
"subtitle": "Median household income by county, grouped by region"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
Sized dots
A size channel scales each dot’s radius from a quantitative field. Pass size.scale.range to cap the radius, so tall stacks of dots stay inside the chart area.
{
"mark": "beeswarm",
"data": [
{
"region": "Northeast",
"income": 96.1,
"population": 171
},
{
"region": "Northeast",
"income": 86.6,
"population": 415
},
{
"region": "Northeast",
"income": 64.4,
"population": 21
},
{
"region": "Northeast",
"income": 83.8,
"population": 23
},
{
"region": "Northeast",
"income": 61,
"population": 97
},
{
"region": "Northeast",
"income": 58,
"population": 128
},
// … 42 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
},
"y": {
"field": "region",
"type": "nominal"
},
"color": {
"field": "region",
"type": "nominal"
},
"size": {
"field": "population",
"type": "quantitative",
"scale": {
"range": [
3,
9
]
}
}
},
"legend": {
"show": false
},
"chrome": {
"title": "Bigger counties are drawn as bigger dots",
"subtitle": "Median household income by county, dot size shows population (thousands)"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
},
"y": {
"field": "region",
"type": "nominal"
},
"color": {
"field": "region",
"type": "nominal"
},
"size": {
"field": "population",
"type": "quantitative",
"scale": {
"range": [
3,
9
]
}
}
},
"legend": {
"show": false
},
"chrome": {
"title": "Bigger counties are drawn as bigger dots",
"subtitle": "Median household income by county, dot size shows population (thousands)"
}
};
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 = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
},
"y": {
"field": "region",
"type": "nominal"
},
"color": {
"field": "region",
"type": "nominal"
},
"size": {
"field": "population",
"type": "quantitative",
"scale": {
"range": [
3,
9
]
}
}
},
"legend": {
"show": false
},
"chrome": {
"title": "Bigger counties are drawn as bigger dots",
"subtitle": "Median household income by county, dot size shows population (thousands)"
}
};
</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 = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
},
"y": {
"field": "region",
"type": "nominal"
},
"color": {
"field": "region",
"type": "nominal"
},
"size": {
"field": "population",
"type": "quantitative",
"scale": {
"range": [
3,
9
]
}
}
},
"legend": {
"show": false
},
"chrome": {
"title": "Bigger counties are drawn as bigger dots",
"subtitle": "Median household income by county, dot size shows population (thousands)"
}
};
</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 = [/* 48 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "beeswarm",
"encoding": {
"x": {
"field": "income",
"type": "quantitative",
"axis": {
"title": "Median household income ($K)"
}
},
"y": {
"field": "region",
"type": "nominal"
},
"color": {
"field": "region",
"type": "nominal"
},
"size": {
"field": "population",
"type": "quantitative",
"scale": {
"range": [
3,
9
]
}
}
},
"legend": {
"show": false
},
"chrome": {
"title": "Bigger counties are drawn as bigger dots",
"subtitle": "Median household income by county, dot size shows population (thousands)"
}
};
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 |
|---|---|
mark |
"beeswarm" draws one dodged dot per row. |
encoding.x or encoding.y |
The quantitative value axis. x gives a horizontal swarm and y a vertical one. |
encoding.y or encoding.x |
Optional. A nominal or ordinal field that splits the swarm into one lane per category. |
encoding.color |
Optional. A categorical grouping, or a quantitative field for a sequential gradient on the dots. |
encoding.size |
Optional. A quantitative field that scales the dot radius. |
encoding.size.scale.range |
Caps the radius range of the dots. |
legend.show |
Set to false to hide a legend the lanes already make redundant. |
Related
- Tick strip: one tick per observation, without dodging.
- Histogram: bin and count the values.
- Density: a smoothed outline of the values.
- Scatter: place dots by two numbers instead of one.
- Lollipop: one dot per category rather than per observation.
- Marks reference: the channels and options each mark type takes.