On this page

Coords

Plot coordinate systems. Compose declaration-only shells such as CoordFlip and CoordFixed, or portable helpers such as coordTransform. Coords are a REPLACE family (last registration wins). Narrative guide: Facets and coordinates.

6 coords

All coords

How to set a coord

Prefer a typed shell as a child of <GGPlot>. Coords replace whole; only one coord is active. Omit coord for default Cartesian.

import { GGPlot, GeomCol, CoordFlip } from "@ggsvelte/svelte";

<GGPlot data={rows} aes={{ x: "category", y: "value" }}>
  <GeomCol />
  <CoordFlip />
</GGPlot>

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

import { coordFixed, coordTransform } from "@ggsvelte/spec";

coordFixed({ ratio: 1 })
// → { type: "fixed" }

coordTransform({ x: "log10", y: { transform: "sqrt", reverse: true } })
// → { type: "transform", x: { transform: "log10" }, y: { transform: "sqrt", reverse: true } }

Builder sugar includes .coordFlip(), .coordTransform(…), .coordFixed(…), .coordEqual(…), and .coordSf(…), plus .coord(…) for a full CoordSpec or the "flip" shorthand.

Escape hatch

For a computed fragment, use <Coord value={spec} /> where value is a CoordSpec or "flip". Named shells are preferred when the form is known at authoring time.

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

const coord = condition ? { type: "flip" } : { type: "fixed", ratio: 2 };

<GGPlot data={rows} aes={{ x: "x", y: "y" }}>
  <GeomPoint />
  <Coord value={coord} />
</GGPlot>

<CoordCartesian /> registers { type: "cartesian" }, which normalize() drops when bare — useful mid-migration under REPLACE so a child can clear a prior flip or fixed coord.