# Magnet clusters

> Use magnet clusters to sort items into groups you can see: each item is a dot pulled to its group's magnet, and switching what a dot weighs re-sorts the story.

- Data type: Shares of a total (`parts`)
- Pro · not released yet: its code is not available; try it on its page, or use a free chart of the same data type (`parts`)
- Example: **Most countries are high-income, but three in four people live in middle-income ones** (Countries by World Bank income group; dot area is population, 2025)
- How to read it: Each dot is one country, pulled to the magnet for its income group; switch to one dot per country to count countries instead of people.
- Interactive: regroup
- Phone: Adapts to mobile (Draws its own phone layout below 520px) · Video formats: 16:9 (best 16:9)

## Use it when
- sorting 30 to 300 items into 2 to 6 groups
- the count of items and their total size tell different stories
- a lively alternative to a grouped bar

## Avoid it when
- the exact size of each cluster matters (use bars)
- items belong to more than one group
- more than six groups

## Fields (data.json)
- `groups` (category): World Bank income groups, poorest first
- `countries[][0]` (place): country
- `countries[][1]` (id): index into groups
- `countries[][2]` (number, unit "people", format count): population
- `year` (year): population year

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
- switch between dot size by people and one dot per country
- hover or tap a dot to read the country
- hover a group's label for its totals
- Motion: Dots start scattered like iron filings, then a force simulation pulls each to its magnet; switching the sizing makes the clusters swell or shrink and repack.
- Sound: A whoosh as the magnets switch on; a pop on hover. Quiet while it draws and between steps; mute it from its card. (sound is off until the viewer turns it on)
- Physics settings: gravity, drag, size, seed (the Studio's Physics section, a look's `physics`, or `render --physics key=value`; docs/look-format.md)

## Example spec
```json
{
  "chart": "magnet-clusters",
  "title": "Most countries are high-income, but three in four people live in middle-income ones",
  "subtitle": "Countries by World Bank income group; dot area is population, 2025",
  "data": "/charts/magnet-clusters.data.json"
}
```

## Source
World Bank country classifications and Population, total (SP.POP.TOTL), World Bank (World Development Indicators API) (CC BY 4.0), retrieved 2026-12-01: https://api.worldbank.org/v2/country?format=json&per_page=400

Note: Shares are of the 217 economies the World Bank classifies and reports a population for. Group thresholds are set each July by gross national income per person.

Live: /charts/magnet-clusters · Manifest: /charts/magnet-clusters.json · Tags: force, clusters, groups, beeswarm, income, population, economics
