# Annotations

> Text callouts with connectors, reference lines and shaded ranges, placed in data coordinates to point at the story.

An annotation is a note placed in data coordinates, so it stays on its point at every width. A `text` annotation with a connector points at one mark.

```json
{
  "mark": {
    "type": "point",
    "fill": "#0e7490",
    "size": 6,
    "trendline": false
  },
  "data": [
    {
      "country": "India",
      "gdpPerCapita": 9818,
      "lifeExpectancy": 68.3
    },
    {
      "country": "China",
      "gdpPerCapita": 23846,
      "lifeExpectancy": 76.1
    },
    {
      "country": "United States",
      "gdpPerCapita": 75489,
      "lifeExpectancy": 79.2
    },
    {
      "country": "Indonesia",
      "gdpPerCapita": 14470,
      "lifeExpectancy": 69
    },
    {
      "country": "Brazil",
      "gdpPerCapita": 19652,
      "lifeExpectancy": 75.3
    },
    {
      "country": "Mexico",
      "gdpPerCapita": 22040,
      "lifeExpectancy": 76.9
    },
    {
      "country": "Japan",
      "gdpPerCapita": 46107,
      "lifeExpectancy": 83.6
    },
    {
      "country": "Germany",
      "gdpPerCapita": 63676,
      "lifeExpectancy": 80.8
    },
    {
      "country": "United Kingdom",
      "gdpPerCapita": 53139,
      "lifeExpectancy": 81.4
    },
    {
      "country": "France",
      "gdpPerCapita": 54799,
      "lifeExpectancy": 82.4
    },
    {
      "country": "South Korea",
      "gdpPerCapita": 55071,
      "lifeExpectancy": 81.9
    },
    {
      "country": "Canada",
      "gdpPerCapita": 58321,
      "lifeExpectancy": 82.2
    }
  ],
  "encoding": {
    "x": {
      "field": "gdpPerCapita",
      "type": "quantitative",
      "axis": {
        "title": "GDP per person (PPP, constant international $)",
        "format": "$,.0f"
      }
    },
    "y": {
      "field": "lifeExpectancy",
      "type": "quantitative",
      "axis": {
        "title": "Life expectancy at birth (years)"
      }
    },
    "tooltip": {
      "field": "country",
      "type": "nominal",
      "title": "Country"
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": 75489,
      "y": 79.2,
      "text": "**United States**\n$75,489 per person, 79.2 years",
      "anchor": "bottom",
      "offset": {
        "dx": -40,
        "dy": 40
      },
      "connector": "curve"
    }
  ],
  "chrome": {
    "title": "The US has the highest income of these 12 countries, but six of them live longer",
    "subtitle": "GDP per person against life expectancy at birth in 12 large economies"
  }
}
```

## Text callout

The callout sits at the US point, `x: 75489` and `y: 79.2`. `offset` moves the label 40 pixels left and down from it, `anchor: "bottom"` puts the label below the point (`anchor` sets which side of the point the label sits on), and `connector: "curve"` draws a curved leader with a ring on the point. `\n` breaks the text into two lines and `**United States**` sets the name in bold.

## Reference line

```json
{
  "mark": {
    "type": "bar",
    "fill": "#0e7490"
  },
  "data": [
    {
      "month": "Jan",
      "high": 9.3
    },
    {
      "month": "Feb",
      "high": 9.2
    },
    {
      "month": "Mar",
      "high": 10.8
    },
    {
      "month": "Apr",
      "high": 19
    },
    {
      "month": "May",
      "high": 22.1
    },
    {
      "month": "Jun",
      "high": 25.4
    },
    {
      "month": "Jul",
      "high": 30.2
    },
    {
      "month": "Aug",
      "high": 27.6
    },
    {
      "month": "Sep",
      "high": 24.3
    },
    {
      "month": "Oct",
      "high": 19.3
    },
    {
      "month": "Nov",
      "high": 11.8
    },
    {
      "month": "Dec",
      "high": 9.8
    }
  ],
  "encoding": {
    "x": {
      "field": "month",
      "type": "ordinal",
      "sort": null,
      "axis": {
        "title": "2023"
      }
    },
    "y": {
      "field": "high",
      "type": "quantitative",
      "axis": {
        "title": "Average daily high",
        "format": ".0f",
        "labelSuffix": "°C"
      }
    }
  },
  "labels": false,
  "annotations": [
    {
      "type": "refline",
      "y": 18.233333333333338,
      "label": "Average of the monthly highs, 18.2°C",
      "style": "dashed",
      "strokeWidth": 1.5
    }
  ],
  "chrome": {
    "title": "Seven months of 2023 averaged highs above 18.2°C, the average of Central Park's 12 monthly highs",
    "subtitle": "Average daily high by month, Central Park, New York, 2023 (°C)"
  }
}
```

A `refline` draws a line across the plot at one value. Set `y` for a horizontal line or `x` for a vertical one. This one marks the average of the 12 monthly highs, 18.2°C. The demo module computes it from the rows, so the line and its label always match the data. `style: "dashed"` keeps it visually separate from the bars.

## Shaded range

```json
{
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "data": [
    {
      "date": "2019-01-01",
      "rate": 1.6
    },
    {
      "date": "2019-04-01",
      "rate": 2
    },
    {
      "date": "2019-07-01",
      "rate": 1.8
    },
    {
      "date": "2019-10-01",
      "rate": 1.8
    },
    {
      "date": "2020-01-01",
      "rate": 2.5
    },
    {
      "date": "2020-04-01",
      "rate": 0.3
    },
    {
      "date": "2020-07-01",
      "rate": 1
    },
    {
      "date": "2020-10-01",
      "rate": 1.2
    },
    {
      "date": "2021-01-01",
      "rate": 1.4
    },
    {
      "date": "2021-04-01",
      "rate": 4.2
    },
    {
      "date": "2021-07-01",
      "rate": 5.4
    },
    {
      "date": "2021-10-01",
      "rate": 6.2
    },
    {
      "date": "2022-01-01",
      "rate": 7.5
    },
    {
      "date": "2022-04-01",
      "rate": 8.3
    },
    {
      "date": "2022-07-01",
      "rate": 8.5
    },
    {
      "date": "2022-10-01",
      "rate": 7.7
    },
    {
      "date": "2023-01-01",
      "rate": 6.4
    },
    {
      "date": "2023-04-01",
      "rate": 4.9
    },
    {
      "date": "2023-07-01",
      "rate": 3.2
    },
    {
      "date": "2023-10-01",
      "rate": 3.2
    },
    {
      "date": "2024-01-01",
      "rate": 3.1
    },
    {
      "date": "2024-04-01",
      "rate": 3.4
    },
    {
      "date": "2024-07-01",
      "rate": 2.9
    },
    {
      "date": "2024-10-01",
      "rate": 2.6
    }
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "format": "%Y",
        "tickCount": 6
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "scale": {
        "domain": [
          0,
          10
        ]
      },
      "axis": {
        "title": "Change from a year earlier",
        "format": ".0f",
        "labelSuffix": "%"
      }
    }
  },
  "annotations": [
    {
      "type": "range",
      "x1": "2021-07-01",
      "x2": "2023-01-01",
      "label": "Above 5%",
      "opacity": 0.12
    }
  ],
  "chrome": {
    "title": "US inflation stayed above 5% for seven straight quarters, from mid-2021 to early 2023",
    "subtitle": "Consumer price index, % change from a year earlier, quarterly, 2019–2024"
  }
}
```

A `range` shades a stretch of the axis between `x1` and `x2`, or `y1` and `y2`, with an optional `label`. Here it covers the seven quarters when inflation ran above 5%, from the third quarter of 2021 to the first quarter of 2023. `opacity` keeps the fill light enough that the line stays easy to read through it, and a y `domain` of 0 to 10 leaves room for the label above the peak.

## Highlighted series

```json
{
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "data": [
    {
      "year": "2016",
      "source": "Coal",
      "share": 31.2
    },
    {
      "year": "2016",
      "source": "Gas",
      "share": 34.8
    },
    {
      "year": "2016",
      "source": "Nuclear",
      "share": 20.3
    },
    {
      "year": "2016",
      "source": "Hydro",
      "share": 6.6
    },
    {
      "year": "2016",
      "source": "Wind",
      "share": 5.7
    },
    {
      "year": "2016",
      "source": "Solar",
      "share": 1.4
    },
    {
      "year": "2017",
      "source": "Coal",
      "share": 30.7
    },
    {
      "year": "2017",
      "source": "Gas",
      "share": 33
    },
    {
      "year": "2017",
      "source": "Nuclear",
      "share": 20.5
    },
    {
      "year": "2017",
      "source": "Hydro",
      "share": 7.5
    },
    {
      "year": "2017",
      "source": "Wind",
      "share": 6.5
    },
    {
      "year": "2017",
      "source": "Solar",
      "share": 2
    },
    {
      "year": "2018",
      "source": "Coal",
      "share": 28.2
    },
    {
      "year": "2018",
      "source": "Gas",
      "share": 36
    },
    {
      "year": "2018",
      "source": "Nuclear",
      "share": 19.8
    },
    {
      "year": "2018",
      "source": "Hydro",
      "share": 7
    },
    {
      "year": "2018",
      "source": "Wind",
      "share": 6.7
    },
    {
      "year": "2018",
      "source": "Solar",
      "share": 2.3
    },
    {
      "year": "2019",
      "source": "Coal",
      "share": 23.9
    },
    {
      "year": "2019",
      "source": "Gas",
      "share": 39.2
    },
    {
      "year": "2019",
      "source": "Nuclear",
      "share": 20
    },
    {
      "year": "2019",
      "source": "Hydro",
      "share": 7
    },
    {
      "year": "2019",
      "source": "Wind",
      "share": 7.3
    },
    {
      "year": "2019",
      "source": "Solar",
      "share": 2.6
    },
    {
      "year": "2020",
      "source": "Coal",
      "share": 19.6
    },
    {
      "year": "2020",
      "source": "Gas",
      "share": 41.3
    },
    {
      "year": "2020",
      "source": "Nuclear",
      "share": 20.1
    },
    {
      "year": "2020",
      "source": "Hydro",
      "share": 7.1
    },
    {
      "year": "2020",
      "source": "Wind",
      "share": 8.6
    },
    {
      "year": "2020",
      "source": "Solar",
      "share": 3.3
    },
    {
      "year": "2021",
      "source": "Coal",
      "share": 22.2
    },
    {
      "year": "2021",
      "source": "Gas",
      "share": 39
    },
    {
      "year": "2021",
      "source": "Nuclear",
      "share": 19.3
    },
    {
      "year": "2021",
      "source": "Hydro",
      "share": 6.1
    },
    {
      "year": "2021",
      "source": "Wind",
      "share": 9.3
    },
    {
      "year": "2021",
      "source": "Solar",
      "share": 4.1
    },
    {
      "year": "2022",
      "source": "Coal",
      "share": 19.9
    },
    {
      "year": "2022",
      "source": "Gas",
      "share": 40.4
    },
    {
      "year": "2022",
      "source": "Nuclear",
      "share": 18.5
    },
    {
      "year": "2022",
      "source": "Hydro",
      "share": 6
    },
    {
      "year": "2022",
      "source": "Wind",
      "share": 10.4
    },
    {
      "year": "2022",
      "source": "Solar",
      "share": 4.9
    },
    {
      "year": "2023",
      "source": "Coal",
      "share": 16.2
    },
    {
      "year": "2023",
      "source": "Gas",
      "share": 43.5
    },
    {
      "year": "2023",
      "source": "Nuclear",
      "share": 18.6
    },
    {
      "year": "2023",
      "source": "Hydro",
      "share": 5.8
    },
    {
      "year": "2023",
      "source": "Wind",
      "share": 10.1
    },
    {
      "year": "2023",
      "source": "Solar",
      "share": 5.8
    }
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "axis": {
        "title": "Share of generation",
        "format": ".0f",
        "labelSuffix": "%"
      }
    },
    "color": {
      "field": "source",
      "type": "nominal",
      "highlight": "Coal"
    }
  },
  "endpointLabels": {
    "content": "label"
  },
  "seriesStyles": {
    "Coal": {
      "strokeWidth": 3
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2020",
      "y": 19.6,
      "text": "Coal fell below **20%** in 2020",
      "anchor": "bottom",
      "offset": {
        "dx": 0,
        "dy": 28
      },
      "connector": true
    }
  ],
  "chrome": {
    "title": "Coal's share of generation from the six main sources nearly halved between 2016 and 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar (%). Coal went from 31.2% in 2016 to 16.2% in 2023."
  }
}
```

`highlight: "Coal"` on the color channel keeps coal in its color and greys out the other five series. `seriesStyles` makes the coal line thicker, and one text annotation names the year it first fell below 20%. Keep a chart to three annotations or fewer; one that needs more usually holds two findings and reads better as two charts.

## Fields that matter

| Field | What it does |
| --- | --- |
| `type` | `"text"`, `"refline"` or `"range"`. |
| `x`, `y` | Data coordinates of a text note or reference line. |
| `x1`, `x2`, `y1`, `y2` | The ends of a range. |
| `text`, `label` | The note text. `**bold**` spans and `\n` line breaks work in `text`. |
| `connector` | `true`, `"curve"`, `"drop-line"` or `{ type, arrow }`. |
| `anchor`, `offset` | Which side of the point the label sits on, and the label's pixel offset. |
| `style` | `"solid"`, `"dashed"` or `"dotted"` for a reference line. |
| `encoding.color.highlight` | One or more series to keep in color while the rest turn grey. |

## Related

- [Line](/docs/change-over-time/line/) combines callouts, reference lines and ranges on time series.
- [Scatter](/docs/correlation/scatter/) labels outliers with callouts.
- [Annotations reference](/docs/spec/annotations/) lists every annotation field.
