# 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](/docs/correlation/scatter/) is simpler to read. When the bubbles represent places, a [symbol map](/docs/maps/symbol-map/) puts them on a map instead. For one number per category, use a [bar chart](/docs/comparison/bar/).

To show how the bubbles moved over the years, add a time field and make it a [bubble playback](/docs/correlation/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.

```json
{
  "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"
    },
    {
      "country": "Germany",
      "co2": 8.1,
      "renewables": 42,
      "pop": 84,
      "continent": "Europe"
    },
    {
      "country": "France",
      "co2": 4.5,
      "renewables": 25,
      "pop": 68,
      "continent": "Europe"
    },
    {
      "country": "UK",
      "co2": 5,
      "renewables": 38,
      "pop": 67,
      "continent": "Europe"
    },
    {
      "country": "Sweden",
      "co2": 3.5,
      "renewables": 60,
      "pop": 10,
      "continent": "Europe"
    },
    {
      "country": "Norway",
      "co2": 7.5,
      "renewables": 98,
      "pop": 5,
      "continent": "Europe"
    },
    {
      "country": "Poland",
      "co2": 8.3,
      "renewables": 17,
      "pop": 38,
      "continent": "Europe"
    },
    {
      "country": "Italy",
      "co2": 5.3,
      "renewables": 20,
      "pop": 59,
      "continent": "Europe"
    },
    {
      "country": "Spain",
      "co2": 5.1,
      "renewables": 35,
      "pop": 48,
      "continent": "Europe"
    },
    {
      "country": "USA",
      "co2": 14.7,
      "renewables": 21,
      "pop": 339,
      "continent": "Americas"
    },
    {
      "country": "Canada",
      "co2": 14.3,
      "renewables": 68,
      "pop": 40,
      "continent": "Americas"
    },
    {
      "country": "Brazil",
      "co2": 2.3,
      "renewables": 85,
      "pop": 216,
      "continent": "Americas"
    },
    {
      "country": "Mexico",
      "co2": 3.6,
      "renewables": 18,
      "pop": 128,
      "continent": "Americas"
    },
    {
      "country": "Argentina",
      "co2": 4,
      "renewables": 14,
      "pop": 46,
      "continent": "Americas"
    },
    {
      "country": "South Africa",
      "co2": 7.4,
      "renewables": 7,
      "pop": 60,
      "continent": "Africa"
    },
    {
      "country": "Nigeria",
      "co2": 0.6,
      "renewables": 19,
      "pop": 223,
      "continent": "Africa"
    },
    {
      "country": "Ethiopia",
      "co2": 0.2,
      "renewables": 92,
      "pop": 126,
      "continent": "Africa"
    },
    {
      "country": "Kenya",
      "co2": 0.4,
      "renewables": 80,
      "pop": 55,
      "continent": "Africa"
    },
    {
      "country": "Egypt",
      "co2": 2.4,
      "renewables": 12,
      "pop": 111,
      "continent": "Africa"
    }
  ],
  "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)."
  }
}
```

## 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.

```json
{
  "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"
    },
    {
      "country": "Germany",
      "co2": 8.1,
      "renewables": 42,
      "pop": 84,
      "continent": "Europe"
    },
    {
      "country": "France",
      "co2": 4.5,
      "renewables": 25,
      "pop": 68,
      "continent": "Europe"
    },
    {
      "country": "UK",
      "co2": 5,
      "renewables": 38,
      "pop": 67,
      "continent": "Europe"
    },
    {
      "country": "Sweden",
      "co2": 3.5,
      "renewables": 60,
      "pop": 10,
      "continent": "Europe"
    },
    {
      "country": "Norway",
      "co2": 7.5,
      "renewables": 98,
      "pop": 5,
      "continent": "Europe"
    },
    {
      "country": "Poland",
      "co2": 8.3,
      "renewables": 17,
      "pop": 38,
      "continent": "Europe"
    },
    {
      "country": "Italy",
      "co2": 5.3,
      "renewables": 20,
      "pop": 59,
      "continent": "Europe"
    },
    {
      "country": "Spain",
      "co2": 5.1,
      "renewables": 35,
      "pop": 48,
      "continent": "Europe"
    },
    {
      "country": "USA",
      "co2": 14.7,
      "renewables": 21,
      "pop": 339,
      "continent": "Americas"
    },
    {
      "country": "Canada",
      "co2": 14.3,
      "renewables": 68,
      "pop": 40,
      "continent": "Americas"
    },
    {
      "country": "Brazil",
      "co2": 2.3,
      "renewables": 85,
      "pop": 216,
      "continent": "Americas"
    },
    {
      "country": "Mexico",
      "co2": 3.6,
      "renewables": 18,
      "pop": 128,
      "continent": "Americas"
    },
    {
      "country": "Argentina",
      "co2": 4,
      "renewables": 14,
      "pop": 46,
      "continent": "Americas"
    },
    {
      "country": "South Africa",
      "co2": 7.4,
      "renewables": 7,
      "pop": 60,
      "continent": "Africa"
    },
    {
      "country": "Nigeria",
      "co2": 0.6,
      "renewables": 19,
      "pop": 223,
      "continent": "Africa"
    },
    {
      "country": "Ethiopia",
      "co2": 0.2,
      "renewables": 92,
      "pop": 126,
      "continent": "Africa"
    },
    {
      "country": "Kenya",
      "co2": 0.4,
      "renewables": 80,
      "pop": 55,
      "continent": "Africa"
    },
    {
      "country": "Egypt",
      "co2": 2.4,
      "renewables": 12,
      "pop": 111,
      "continent": "Africa"
    }
  ],
  "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)."
  }
}
```

## 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.

```json
{
  "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
    },
    {
      "country": "France",
      "gdpPerCapita": 38625,
      "lifeExpectancy": 82.5,
      "region": "Europe",
      "pop": 67
    },
    {
      "country": "United Kingdom",
      "gdpPerCapita": 40285,
      "lifeExpectancy": 81.3,
      "region": "Europe",
      "pop": 67
    },
    {
      "country": "Italy",
      "gdpPerCapita": 31676,
      "lifeExpectancy": 83.5,
      "region": "Europe",
      "pop": 59
    },
    {
      "country": "Spain",
      "gdpPerCapita": 27057,
      "lifeExpectancy": 83.6,
      "region": "Europe",
      "pop": 47
    },
    {
      "country": "Japan",
      "gdpPerCapita": 39313,
      "lifeExpectancy": 84.6,
      "region": "Asia",
      "pop": 125
    },
    {
      "country": "South Korea",
      "gdpPerCapita": 31489,
      "lifeExpectancy": 83.5,
      "region": "Asia",
      "pop": 52
    },
    {
      "country": "China",
      "gdpPerCapita": 10500,
      "lifeExpectancy": 78.2,
      "region": "Asia",
      "pop": 1412
    },
    {
      "country": "India",
      "gdpPerCapita": 1901,
      "lifeExpectancy": 70.2,
      "region": "Asia",
      "pop": 1408
    },
    {
      "country": "Indonesia",
      "gdpPerCapita": 3870,
      "lifeExpectancy": 71.9,
      "region": "Asia",
      "pop": 273
    },
    {
      "country": "South Africa",
      "gdpPerCapita": 5091,
      "lifeExpectancy": 64.1,
      "region": "Africa",
      "pop": 60
    },
    {
      "country": "Nigeria",
      "gdpPerCapita": 2066,
      "lifeExpectancy": 54.7,
      "region": "Africa",
      "pop": 211
    },
    {
      "country": "Egypt",
      "gdpPerCapita": 3019,
      "lifeExpectancy": 72,
      "region": "Africa",
      "pop": 104
    },
    {
      "country": "Ethiopia",
      "gdpPerCapita": 926,
      "lifeExpectancy": 66.6,
      "region": "Africa",
      "pop": 118
    },
    {
      "country": "Kenya",
      "gdpPerCapita": 1838,
      "lifeExpectancy": 66.7,
      "region": "Africa",
      "pop": 54
    }
  ],
  "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)."
  }
}
```

## 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](/docs/correlation/scatter/): the two-number form.
- [Bubble playback](/docs/correlation/bubble-playback/): the same chart played year by year.
- [Trendlines](/docs/correlation/trendlines/): control the fitted line.
- [Symbol map](/docs/maps/symbol-map/): bubbles placed on a map.
- [Heatmap](/docs/correlation/heatmap/): intensity in a grid of categories.
- [Bar](/docs/comparison/bar/): compare one number across categories.
- [Encoding reference](/docs/spec/encoding/): every channel with its scale and axis settings.
