# MicroScatter (/docs/charts/micro-scatter)

MicroScatter answers "are these two variables related?" — the relationship story no other micro chart tells. Dots render
at 75% opacity so overplot reads as density instead of lying by occlusion, and duplicates are never jittered: position
is the encoding.

```tsx
<span className="text-lg">
  {"Latency and error rate "}
  <MicroScatter
    data={Array.from({ length: 24 }, (_, i) => ({ x: i, y: i * 3 + ((i * 7) % 5) * 6 }))}
    title="Latency vs error rate"
    style={{ width: "3em", height: "1.8em" }}
  />
  {" correlate strongly."}
</span>
```

## Install

```tsx
import { MicroScatter } from "@microcharts/react/micro-scatter";

<MicroScatter data={pairs} title="Latency vs error rate" />
```

Setup (package + stylesheet): [Quickstart](/docs/quickstart#set-up-with-an-ai-agent) or paste [`/agent-setup.md`](/agent-setup.md) into your agent.


## When to use it

- **Good for** — correlation in a sentence, two-metric relationships in KPI cards.
- **Avoid for** — more than 60 points (bin instead) or ordered time series (Sparkline).


## Variants

```tsx
// least-squares, linear only — never smoothed
<MicroScatter data={pairs} trend />
```

```tsx
<MicroScatter data={pairs} focal={12} />
```

## Edge cases

```tsx
<MicroScatter data={[]} title="No pairs" />
```

```tsx
<MicroScatter data={[{ x: 1, y: 2 }, { x: 2, y: 3 }]} title="Two points" />
```

```tsx
<MicroScatter data={[{ x: 5, y: 5 }, { x: 5, y: 5 }, { x: 1, y: 8 }]} />
```

Empty data draws just the frame with "No data." as the summary. Under 3 points (or a zero-variance cloud) states the
count and stops — no correlation claim without enough evidence to back it. Coincident points are never jittered apart:
they overlap exactly, and at 75% dot opacity the overlap itself reads as extra density rather than hiding a point.


## Why this default

Axes are unlabeled at this scale, so `title` must name both variables, the way the hero demo above does. The summary's
relationship words are a documented heuristic on |r| (≥ 0.7 strong, ≥ 0.4 moderate, ≥ 0.2 weak), and whenever a
relationship word appears, r appears beside it: claim and evidence travel together. Fewer than 3 points, or a
zero-variance cloud, makes no claim at all.

## Accessibility

The accessible name is the count plus the evidence-backed relationship — **"24 points. Strong positive relationship (r
0.93)."** — or just **"2 points."** when no claim is honest. The interactive entry steps points ordered by x and
announces each formatted pair.

The interactive entry follows the shared [interaction contract](/docs/accessibility#one-interaction-contract):
arrow keys rove between units on both axes, `Home` and `End` jump to the ends, and a click, tap, `Enter` or
`Space` selects a unit — pinning its readout so it survives blur, until you select it again or press `Escape`.
On touch, a tap pins and a drag scrubs.

## Props

| Prop | Type | Description |
| --- | --- | --- |
| `data` (required) | `{ x; y }[]` | Unordered pairs. |
| `trend` | `boolean` | Least-squares line — linear only, never smoothed. |
| `focal` | `number` | Accent one point — "this one, among all of them". |
| `xDomain` | `[number, number]` | X scale (domain keeps its grammar meaning: y). |
| `domain` | `[number, number]` | Y scale — the shared grammar name, paired with xDomain. |
| `r` | `number` | Dot radius, clamped [1, 3]. |
| `animate` | `boolean` | (interactive) Opt-in entrance motion when the chart mounts client-side — add `import "@microcharts/react/motion"` once. Inert on the server, on hydrated server HTML, and under `prefers-reduced-motion`. |

Plus the shared grammar — `data`, `domain`, `color`, `title`, `summary`, `format` — and the layout props (`width`, `height`, `className`, `style`) that every chart accepts. Interactive entries also share `animate` and `live`, and — wherever a chart has more than one navigable unit — `onActive`, `onSelect`, `selectedIndex` and `defaultSelectedIndex`; and — wherever the chart shows a hover value — `readout`. See [the shared grammar](/docs/quickstart#the-shared-grammar).
