Guides and legends

Appearance-only guides keyed by aesthetic. Compose declaration-only shells such as GuideLegend and GuideColorbar, or portable helpers such as guideLegend. Placement here is guide position (right/bottom) — not geom position adjustments (stack, dodge, jitter).

5 guides

All guides

How to set a guide

Prefer a typed shell with a channel prop. Guides merge by channel; the value at a channel is replaced whole. Top-level guide children win over a scale-local guide on the same aesthetic.

import { GGPlot, GeomPoint, GuideLegend } from "@ggsvelte/svelte";

<GGPlot data={rows} aes={{ x: "displ", y: "hwy", color: "class" }}>
  <GeomPoint />
  <GuideLegend channel="color" position="bottom" direction="horizontal" />
</GGPlot>

Portable helpers assemble the same JSON for the builder or normalize():

import { guideLegend, guides } from "@ggsvelte/spec";

guides({ color: guideLegend({ position: "bottom" }) })
// → { guides: { color: { type: "legend", position: "bottom" } } }

For a computed multi-channel bag, use the escape hatch <Guides value={…} />. Suppress one channel with GuideNone.

Legend focus and clear recovery

Discrete color and fill legends can host interaction controls when legendFocus or legendFilter is enabled on the plot. Focus is presentation emphasis only; Clear legend focus restores the unfocused view without changing data. Authoring the guide itself is separate — see GuideLegend, the interaction reference, and the legend focus example.