Bubble
Add a third number to a scatter as dot size, then color the bubbles by group and annotate the ones that matter with callouts and a reference line.
A bubble chart is a scatter chart where a third number sets each dot’s size. Position carries two fields and area carries the third, such as population, so a reader sees how many people sit behind each point.
If you only have two numbers, a scatter chart is simpler to read. When the bubbles represent places, a symbol map puts them on a map instead. For one number per category, use a bar chart.
To show how the bubbles moved over the years, add a time field and make it a bubble playback.
A basic bubble chart
A bubble chart is a point mark with a size channel. Put a quantitative field on size and the chart maps it to circle area. It also gets the default trend line a point mark draws.
{
"mark": "point",
"data": [
{
"country": "China",
"co2": 8,
"renewables": 16,
"pop": 1425,
"continent": "Asia"
},
{
"country": "India",
"co2": 2,
"renewables": 22,
"pop": 1428,
"continent": "Asia"
},
{
"country": "Japan",
"co2": 8.5,
"renewables": 12,
"pop": 124,
"continent": "Asia"
},
{
"country": "South Korea",
"co2": 12.1,
"renewables": 5,
"pop": 52,
"continent": "Asia"
},
{
"country": "Indonesia",
"co2": 2.3,
"renewables": 17,
"pop": 277,
"continent": "Asia"
},
{
"country": "Thailand",
"co2": 3.8,
"renewables": 15,
"pop": 72,
"continent": "Asia"
},
// … 18 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "co2",
"type": "quantitative",
"axis": {
"title": "CO2 emissions per capita (tonnes)"
}
},
"y": {
"field": "renewables",
"type": "quantitative",
"axis": {
"title": "Renewable electricity share (%)"
}
},
"size": {
"field": "pop",
"type": "quantitative"
}
},
"chrome": {
"title": "Per-person emissions vary widely at every renewable share",
"subtitle": "CO2 emissions per capita vs. share of electricity from renewables, 2023. Circle size = population (millions)."
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 24 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "co2",
"type": "quantitative",
"axis": {
"title": "CO2 emissions per capita (tonnes)"
}
},
"y": {
"field": "renewables",
"type": "quantitative",
"axis": {
"title": "Renewable electricity share (%)"
}
},
"size": {
"field": "pop",
"type": "quantitative"
}
},
"chrome": {
"title": "Per-person emissions vary widely at every renewable share",
"subtitle": "CO2 emissions per capita vs. share of electricity from renewables, 2023. Circle size = population (millions)."
}
};
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 = [/* 24 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "co2",
"type": "quantitative",
"axis": {
"title": "CO2 emissions per capita (tonnes)"
}
},
"y": {
"field": "renewables",
"type": "quantitative",
"axis": {
"title": "Renewable electricity share (%)"
}
},
"size": {
"field": "pop",
"type": "quantitative"
}
},
"chrome": {
"title": "Per-person emissions vary widely at every renewable share",
"subtitle": "CO2 emissions per capita vs. share of electricity from renewables, 2023. Circle size = population (millions)."
}
};
</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 = [/* 24 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "co2",
"type": "quantitative",
"axis": {
"title": "CO2 emissions per capita (tonnes)"
}
},
"y": {
"field": "renewables",
"type": "quantitative",
"axis": {
"title": "Renewable electricity share (%)"
}
},
"size": {
"field": "pop",
"type": "quantitative"
}
},
"chrome": {
"title": "Per-person emissions vary widely at every renewable share",
"subtitle": "CO2 emissions per capita vs. share of electricity from renewables, 2023. Circle size = population (millions)."
}
};
</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 = [/* 24 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "co2",
"type": "quantitative",
"axis": {
"title": "CO2 emissions per capita (tonnes)"
}
},
"y": {
"field": "renewables",
"type": "quantitative",
"axis": {
"title": "Renewable electricity share (%)"
}
},
"size": {
"field": "pop",
"type": "quantitative"
}
},
"chrome": {
"title": "Per-person emissions vary widely at every renewable share",
"subtitle": "CO2 emissions per capita vs. share of electricity from renewables, 2023. Circle size = population (millions)."
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
Color and callouts
A color channel adds a fourth field. Text annotations with connector: true draw a leader line from the label to its bubble, and offset moves the label clear of the cloud.
{
"mark": "point",
"data": [
{
"country": "China",
"co2": 8,
"renewables": 16,
"pop": 1425,
"continent": "Asia"
},
{
"country": "India",
"co2": 2,
"renewables": 22,
"pop": 1428,
"continent": "Asia"
},
{
"country": "Japan",
"co2": 8.5,
"renewables": 12,
"pop": 124,
"continent": "Asia"
},
{
"country": "South Korea",
"co2": 12.1,
"renewables": 5,
"pop": 52,
"continent": "Asia"
},
{
"country": "Indonesia",
"co2": 2.3,
"renewables": 17,
"pop": 277,
"continent": "Asia"
},
{
"country": "Thailand",
"co2": 3.8,
"renewables": 15,
"pop": 72,
"continent": "Asia"
},
// … 18 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "co2",
"type": "quantitative",
"axis": {
"title": "CO2 emissions per capita (tonnes)"
}
},
"y": {
"field": "renewables",
"type": "quantitative",
"axis": {
"title": "Renewable electricity share (%)"
}
},
"size": {
"field": "pop",
"type": "quantitative"
},
"color": {
"field": "continent",
"type": "nominal"
},
"tooltip": [
{
"field": "country",
"type": "nominal",
"title": "Country"
},
{
"field": "co2",
"type": "quantitative",
"title": "CO2 (t/person)"
},
{
"field": "renewables",
"type": "quantitative",
"title": "Renewables (%)"
},
{
"field": "pop",
"type": "quantitative",
"title": "Population (M)"
}
]
},
"annotations": [
{
"type": "text",
"x": 14.7,
"y": 21,
"text": "The US has high emissions\nbut modest renewables",
"connector": true,
"anchor": "left",
"offset": {
"dx": -24,
"dy": -50
}
},
{
"type": "text",
"x": 2.3,
"y": 85,
"text": "Brazil's grid is nearly\nall renewable",
"connector": true,
"anchor": "right",
"offset": {
"dx": 24,
"dy": -18
}
}
],
"chrome": {
"title": "Per-person emissions vary widely at every renewable share",
"subtitle": "CO2 emissions per capita vs. share of electricity from renewables, 2023. Circle size = population (millions)."
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 24 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "co2",
"type": "quantitative",
"axis": {
"title": "CO2 emissions per capita (tonnes)"
}
},
"y": {
"field": "renewables",
"type": "quantitative",
"axis": {
"title": "Renewable electricity share (%)"
}
},
"size": {
"field": "pop",
"type": "quantitative"
},
"color": {
"field": "continent",
"type": "nominal"
},
"tooltip": [
{
"field": "country",
"type": "nominal",
"title": "Country"
},
{
"field": "co2",
"type": "quantitative",
"title": "CO2 (t/person)"
},
{
"field": "renewables",
"type": "quantitative",
"title": "Renewables (%)"
},
{
"field": "pop",
"type": "quantitative",
"title": "Population (M)"
}
]
},
"annotations": [
{
"type": "text",
"x": 14.7,
"y": 21,
"text": "The US has high emissions\nbut modest renewables",
"connector": true,
"anchor": "left",
"offset": {
"dx": -24,
"dy": -50
}
},
{
"type": "text",
"x": 2.3,
"y": 85,
"text": "Brazil's grid is nearly\nall renewable",
"connector": true,
"anchor": "right",
"offset": {
"dx": 24,
"dy": -18
}
}
],
"chrome": {
"title": "Per-person emissions vary widely at every renewable share",
"subtitle": "CO2 emissions per capita vs. share of electricity from renewables, 2023. Circle size = population (millions)."
}
};
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 = [/* 24 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "co2",
"type": "quantitative",
"axis": {
"title": "CO2 emissions per capita (tonnes)"
}
},
"y": {
"field": "renewables",
"type": "quantitative",
"axis": {
"title": "Renewable electricity share (%)"
}
},
"size": {
"field": "pop",
"type": "quantitative"
},
"color": {
"field": "continent",
"type": "nominal"
},
"tooltip": [
{
"field": "country",
"type": "nominal",
"title": "Country"
},
{
"field": "co2",
"type": "quantitative",
"title": "CO2 (t/person)"
},
{
"field": "renewables",
"type": "quantitative",
"title": "Renewables (%)"
},
{
"field": "pop",
"type": "quantitative",
"title": "Population (M)"
}
]
},
"annotations": [
{
"type": "text",
"x": 14.7,
"y": 21,
"text": "The US has high emissions\nbut modest renewables",
"connector": true,
"anchor": "left",
"offset": {
"dx": -24,
"dy": -50
}
},
{
"type": "text",
"x": 2.3,
"y": 85,
"text": "Brazil's grid is nearly\nall renewable",
"connector": true,
"anchor": "right",
"offset": {
"dx": 24,
"dy": -18
}
}
],
"chrome": {
"title": "Per-person emissions vary widely at every renewable share",
"subtitle": "CO2 emissions per capita vs. share of electricity from renewables, 2023. Circle size = population (millions)."
}
};
</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 = [/* 24 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "co2",
"type": "quantitative",
"axis": {
"title": "CO2 emissions per capita (tonnes)"
}
},
"y": {
"field": "renewables",
"type": "quantitative",
"axis": {
"title": "Renewable electricity share (%)"
}
},
"size": {
"field": "pop",
"type": "quantitative"
},
"color": {
"field": "continent",
"type": "nominal"
},
"tooltip": [
{
"field": "country",
"type": "nominal",
"title": "Country"
},
{
"field": "co2",
"type": "quantitative",
"title": "CO2 (t/person)"
},
{
"field": "renewables",
"type": "quantitative",
"title": "Renewables (%)"
},
{
"field": "pop",
"type": "quantitative",
"title": "Population (M)"
}
]
},
"annotations": [
{
"type": "text",
"x": 14.7,
"y": 21,
"text": "The US has high emissions\nbut modest renewables",
"connector": true,
"anchor": "left",
"offset": {
"dx": -24,
"dy": -50
}
},
{
"type": "text",
"x": 2.3,
"y": 85,
"text": "Brazil's grid is nearly\nall renewable",
"connector": true,
"anchor": "right",
"offset": {
"dx": 24,
"dy": -18
}
}
],
"chrome": {
"title": "Per-person emissions vary widely at every renewable share",
"subtitle": "CO2 emissions per capita vs. share of electricity from renewables, 2023. Circle size = population (millions)."
}
};
</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 = [/* 24 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "co2",
"type": "quantitative",
"axis": {
"title": "CO2 emissions per capita (tonnes)"
}
},
"y": {
"field": "renewables",
"type": "quantitative",
"axis": {
"title": "Renewable electricity share (%)"
}
},
"size": {
"field": "pop",
"type": "quantitative"
},
"color": {
"field": "continent",
"type": "nominal"
},
"tooltip": [
{
"field": "country",
"type": "nominal",
"title": "Country"
},
{
"field": "co2",
"type": "quantitative",
"title": "CO2 (t/person)"
},
{
"field": "renewables",
"type": "quantitative",
"title": "Renewables (%)"
},
{
"field": "pop",
"type": "quantitative",
"title": "Population (M)"
}
]
},
"annotations": [
{
"type": "text",
"x": 14.7,
"y": 21,
"text": "The US has high emissions\nbut modest renewables",
"connector": true,
"anchor": "left",
"offset": {
"dx": -24,
"dy": -50
}
},
{
"type": "text",
"x": 2.3,
"y": 85,
"text": "Brazil's grid is nearly\nall renewable",
"connector": true,
"anchor": "right",
"offset": {
"dx": 24,
"dy": -18
}
}
],
"chrome": {
"title": "Per-person emissions vary widely at every renewable share",
"subtitle": "CO2 emissions per capita vs. share of electricity from renewables, 2023. Circle size = population (millions)."
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
A reference line
A refline with y draws a horizontal benchmark in data units, with its label anchored by labelAnchor. Bubbles above the line sit above the benchmark, and their size still shows the population behind each one.
{
"mark": "point",
"data": [
{
"country": "United States",
"gdpPerCapita": 63544,
"lifeExpectancy": 77.3,
"region": "Americas",
"pop": 331
},
{
"country": "Canada",
"gdpPerCapita": 43242,
"lifeExpectancy": 82.2,
"region": "Americas",
"pop": 38
},
{
"country": "Brazil",
"gdpPerCapita": 6797,
"lifeExpectancy": 75.9,
"region": "Americas",
"pop": 213
},
{
"country": "Mexico",
"gdpPerCapita": 8347,
"lifeExpectancy": 75.1,
"region": "Americas",
"pop": 130
},
{
"country": "Argentina",
"gdpPerCapita": 8442,
"lifeExpectancy": 76.5,
"region": "Americas",
"pop": 45
},
{
"country": "Germany",
"gdpPerCapita": 45724,
"lifeExpectancy": 81,
"region": "Europe",
"pop": 83
},
// … 14 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "gdpPerCapita",
"type": "quantitative",
"axis": {
"title": "GDP per capita (USD)",
"format": "$.2~s"
}
},
"y": {
"field": "lifeExpectancy",
"type": "quantitative",
"axis": {
"title": "Life expectancy (years)"
}
},
"color": {
"field": "region",
"type": "nominal"
},
"size": {
"field": "pop",
"type": "quantitative"
}
},
"annotations": [
{
"type": "refline",
"y": 73,
"label": "World avg: 73 yrs",
"labelAnchor": "left",
"style": "dashed",
"stroke": "#64748b",
"strokeWidth": 1
}
],
"chrome": {
"title": "Richer countries live longer, but America is an outlier",
"subtitle": "GDP per capita vs. life expectancy, 2022. Bubble size = population (millions)."
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 20 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "gdpPerCapita",
"type": "quantitative",
"axis": {
"title": "GDP per capita (USD)",
"format": "$.2~s"
}
},
"y": {
"field": "lifeExpectancy",
"type": "quantitative",
"axis": {
"title": "Life expectancy (years)"
}
},
"color": {
"field": "region",
"type": "nominal"
},
"size": {
"field": "pop",
"type": "quantitative"
}
},
"annotations": [
{
"type": "refline",
"y": 73,
"label": "World avg: 73 yrs",
"labelAnchor": "left",
"style": "dashed",
"stroke": "#64748b",
"strokeWidth": 1
}
],
"chrome": {
"title": "Richer countries live longer, but America is an outlier",
"subtitle": "GDP per capita vs. life expectancy, 2022. Bubble size = population (millions)."
}
};
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 = [/* 20 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "gdpPerCapita",
"type": "quantitative",
"axis": {
"title": "GDP per capita (USD)",
"format": "$.2~s"
}
},
"y": {
"field": "lifeExpectancy",
"type": "quantitative",
"axis": {
"title": "Life expectancy (years)"
}
},
"color": {
"field": "region",
"type": "nominal"
},
"size": {
"field": "pop",
"type": "quantitative"
}
},
"annotations": [
{
"type": "refline",
"y": 73,
"label": "World avg: 73 yrs",
"labelAnchor": "left",
"style": "dashed",
"stroke": "#64748b",
"strokeWidth": 1
}
],
"chrome": {
"title": "Richer countries live longer, but America is an outlier",
"subtitle": "GDP per capita vs. life expectancy, 2022. Bubble size = population (millions)."
}
};
</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 = [/* 20 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "gdpPerCapita",
"type": "quantitative",
"axis": {
"title": "GDP per capita (USD)",
"format": "$.2~s"
}
},
"y": {
"field": "lifeExpectancy",
"type": "quantitative",
"axis": {
"title": "Life expectancy (years)"
}
},
"color": {
"field": "region",
"type": "nominal"
},
"size": {
"field": "pop",
"type": "quantitative"
}
},
"annotations": [
{
"type": "refline",
"y": 73,
"label": "World avg: 73 yrs",
"labelAnchor": "left",
"style": "dashed",
"stroke": "#64748b",
"strokeWidth": 1
}
],
"chrome": {
"title": "Richer countries live longer, but America is an outlier",
"subtitle": "GDP per capita vs. life expectancy, 2022. Bubble size = population (millions)."
}
};
</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 = [/* 20 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "gdpPerCapita",
"type": "quantitative",
"axis": {
"title": "GDP per capita (USD)",
"format": "$.2~s"
}
},
"y": {
"field": "lifeExpectancy",
"type": "quantitative",
"axis": {
"title": "Life expectancy (years)"
}
},
"color": {
"field": "region",
"type": "nominal"
},
"size": {
"field": "pop",
"type": "quantitative"
}
},
"annotations": [
{
"type": "refline",
"y": 73,
"label": "World avg: 73 yrs",
"labelAnchor": "left",
"style": "dashed",
"stroke": "#64748b",
"strokeWidth": 1
}
],
"chrome": {
"title": "Richer countries live longer, but America is an outlier",
"subtitle": "GDP per capita vs. life expectancy, 2022. Bubble size = population (millions)."
}
};
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 |
"point" draws one dot per row. |
encoding.x, encoding.y |
The two quantitative fields the bubble is placed by. |
encoding.size |
A quantitative field mapped to circle area. This is what makes it a bubble chart. |
encoding.color |
Optional. A categorical field that colors the bubbles by group. |
encoding.tooltip |
Optional. The fields listed when a bubble is hovered. |
annotations[].connector |
Draws a leader line from a text annotation to its data point. |
annotations[].offset |
Moves a text annotation by dx and dy pixels. |
annotations[].labelAnchor |
Sets the anchor direction of a refline label. |
Related
- Scatter: the two-number form.
- Bubble playback: the same chart played year by year.
- Trendlines: control the fitted line.
- Symbol map: bubbles placed on a map.
- Heatmap: intensity in a grid of categories.
- Bar: compare one number across categories.
- Encoding reference: every channel with its scale and axis settings.