scale-discrete
Discrete scale for any categorical aesthetic.
Keyed to x/y it orders the axis levels; keyed to colour/fill, shape, or linetype it assigns the per-level palette, defaulting to that aesthetic’s built-in set.
Usage
scale-discrete(
..args,
)Parameters
| Parameter | Default | Description |
|---|---|---|
..args |
Named arguments forwarded to the bound scale. |
Keys accepted by ..args:
name: Axis or legend title, as a string or content;none(default) falls back to the mapped column name.limits: Array of level names selecting which levels appear and in which order;none(default) keeps the trained levels. A level name must be a string, because a discrete scale reads a bare number as a position rather than as a level, so quote a numeric level as"1".oob: Handling of rows whose level falls outsidelimits:"drop"(default) removes them;"squish"censors too, since clamping has no meaning on levels.labels: Array of labels in level order, a function of the level returning a string or content, orauto(default) to print the level itself.expand: Padding around the domain as a ratio (5%), a length (5pt), arelative, or a(lo, hi)pair whose sides may each beauto;falseornoneremoves it.auto(default) pads 0.6 of a level slot per side.x/yonly.palette: Array of output values, one per level and recycled when shorter than the level count: colours forcolour/fill, marker keywords forshape, dash keywords forlinetype.auto(default) uses that aesthetic’s built-in set.
Returns
Deferred scale spec consumed by scales.
Examples
Force the level order on a discrete x axis.
#let d = ((grp: "b", y: 3), (grp: "a", y: 5), (grp: "c", y: 2))
#plot(
data: d,
mapping: aes(x: "grp", y: "y"),
layers: (geom-col(),),
scales: scales(x: scale-discrete(limits: ("a", "b", "c"))),
width: 10cm,
height: 6cm,
)