scale-y-discrete

Discrete y scale: axis title, level ordering, and tick labels.

Usage

scale-y-discrete(
  name: none,
  limits: none,
  labels: auto,
  expand: auto,
)

Parameters

Parameter Default Description
name none Axis title. Overrides any name set via labs when both are present.
limits none Array of level names controlling order and inclusion, or none for first-seen order.
labels auto Array of tick labels aligned with limits, or auto.
expand auto Padding around the domain. Accepts a ratio (5%) for proportional breathing room, a length (5pt) for canvas-space padding, a relative (5pt + 5%) for both, or a (lo, hi) 2-tuple for asymmetric padding. auto keeps a 60%-of-slot default on each side; false collapses to zero.

Returns

Scale object consumed by plot.

Examples

Force level order so bars stay in (a, b, c) regardless of input order.

#let d = (
  (grp: "b", x: 3),
  (grp: "a", x: 5),
  (grp: "c", x: 2),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "grp"),
  layers: (geom-point(size: 3pt),),
  scales: (scale-y-discrete(limits: ("a", "b", "c")),),
  width: 10cm,
  height: 6cm,
)

Scatter chart with three points on a discrete y axis whose categories a, b, c sit in forced order from bottom to top via limits.

Scatter chart with three points on a discrete y axis whose categories a, b, c sit in forced order from bottom to top via limits.

Subset the levels (omit "b") to drop a category from the axis without filtering the underlying data.

#let d = (
  (grp: "a", x: 5),
  (grp: "b", x: 3),
  (grp: "c", x: 2),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "grp"),
  layers: (geom-point(size: 3pt),),
  scales: (scale-y-discrete(limits: ("a", "c")),),
  width: 10cm,
  height: 6cm,
)

Scatter chart with two points on a discrete y axis showing only categories a and c after limits drops level b without filtering the data.

Scatter chart with two points on a discrete y axis showing only categories a and c after limits drops level b without filtering the data.

See also

scale-x-discrete, scale-y-continuous.

Back to top