# Density curve

> Use a density curve to show the smooth shape of a distribution, with a marker readers can drag to ask 'how many are below this?'.

- Data type: Many values of one measure (`spread`)
- Free (MIT): install with `npx chartreuse add density`, or registry item `/r/density.json`
- Example: **The typical country's life expectancy rose from 49 years in 1950 to 75 in 2023** (Distribution of countries by life expectancy at birth, years, 1950 and 2023)
- How to read it: Each curve is high where many countries share a life expectancy; drag the marker to read the share of countries below it in each year.
- Interactive: slider
- Phone: Adapts to mobile (Draws its own phone layout below 520px) · Video formats: 16:9 (best 16:9)

## Use it when
- one or two distributions with dozens of values or more
- the overall shape (peaks, skew, shift) is the story
- readers want to test a threshold

## Avoid it when
- fewer than about 30 values (the smoothing invents shape; use a strip plot)
- readers need exact counts (use a histogram)
- values have hard limits the curve would cross

## Fields (data.json)
- `years` (year): the two years compared
- `rows[].year` (year): the year of the value
- `rows[].country` (place): the country
- `rows[].years` (number, unit "years", format decimal): life expectancy at birth, years

Units are the example's: with your own data, set each number field's `unit` and `format` (percent, count, decimal, currency, compact) in the meta you pass to mount, or `chartreuse render --unit field=text --format field=count`. Scales and labels follow your data.

## Interactions, motion, sound
- drag the marker, or click the chart, to read the share of countries below any age
- hover a curve for its median and range
- Motion: The 2023 curve slides out of the 1950 shape to its own place, carrying the marker with it.
- Sound: A settle when the marker reaches the last year. Quiet while it draws, between steps and while you drag the slider; mute it from its card. (sound is off until the viewer turns it on)

## Example spec
```json
{
  "chart": "density",
  "title": "The typical country's life expectancy rose from 49 years in 1950 to 75 in 2023",
  "subtitle": "Distribution of countries by life expectancy at birth, years, 1950 and 2023",
  "data": "/charts/density.data.json"
}
```

## Source
Life expectancy, Our World in Data (UN World Population Prospects; Human Mortality Database; Zijdeman et al.) (CC BY 4.0), retrieved 2026-12-01: https://ourworldindata.org/grapher/life-expectancy

Note: Gaussian kernel, bandwidth 2.6 years. Each country counts once, whatever its size.

Live: /charts/density · Manifest: /charts/density.json · Tags: distribution, KDE, smooth, life expectancy, health, threshold, slider
