# Compare toggle

> Use a compare toggle to switch one chart between two fair ways of measuring, so readers see how the ranking flips.

- Data type: Values per item (`compare`)
- Pro · not released yet: its code is not available; try it on its page, or use a free chart of the same data type (`compare`)
- Example: **China emits the most CO2, but of the ten biggest emitters Saudi Arabia emits the most per person** (Carbon dioxide from fossil fuels and industry, the ten largest emitters, 2025: total tonnes or tonnes per person)
- How to read it: Total ranks countries by all their emissions; Per person divides by population, and the bars re-sort.
- Phone: Adapts to mobile (Draws its own phone layout below 520px) · Video formats: 16:9, 9:16 (best 9:16)

## Use it when
- two measures of the same thing tell different stories (total vs per person, count vs rate)
- the ranking itself changes
- you want readers to discover the flip themselves

## Avoid it when
- the two measures need to be read together (use a scatter)
- the switch changes the set of items, not just their order
- more than two framings (use small multiples)

## Fields (data.json)
- `year` (year): optional: the year, shown in the heading
- `world` (number, unit "tonnes", format compact): optional: the whole's two measures (the world in the example), for the reference line (hints.reference names it); without it the detail compares with the sum of the rows
- `countries[].country` (category): the country
- `countries[].total` (number, unit "tonnes", format compact): the first measure, a total (CO2 emitted, tonnes); its button is hints.names.total, else this description up to the comma
- `countries[].perPerson` (number, unit "tonnes", format decimal): the second measure, the same thing per person or as a rate (CO2 emitted per person, tonnes); its button is hints.names.perPerson

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
- the two measure buttons (Total and Per person) switch the comparison
- hover or tap a bar to read both measures
- Motion: On switching, bars resize to the new scale and slide to their new rank, so you can follow each country.
- Sound: A whoosh on the switch; a pop on hover pitched by rank. Quiet while it draws and between steps; mute it from its card. (sound is off until the viewer turns it on)

## Example spec
```json
{
  "chart": "compare-toggle",
  "title": "China emits the most CO2, but of the ten biggest emitters Saudi Arabia emits the most per person",
  "subtitle": "Carbon dioxide from fossil fuels and industry, the ten largest emitters, 2025: total tonnes or tonnes per person",
  "data": "/charts/compare-toggle.data.json"
}
```

## Source
Annual CO2 emissions and CO2 emissions per capita, Our World in Data (Global Carbon Budget) (CC BY 4.0), retrieved 2026-12-01: https://ourworldindata.org/grapher/co-emissions-per-capita

Note: Territorial emissions: CO2 released inside each country, not counting what its imports cause abroad.

Live: /charts/compare-toggle · Manifest: /charts/compare-toggle.json · Tags: toggle, switch, per capita, ranking, reframe, climate, co2, emissions
