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 (e.g. name, limits, labels, palette).

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,
)

Bar chart with three categorical bars ordered a, b, c on a discrete x axis with heights 5, 3, 2.

Bar chart with three categorical bars ordered a, b, c on a discrete x axis with heights 5, 3, 2.

See also

scales, scale-continuous, scale-manual.

Back to top