scale-fill-manual

Manual discrete fill scale: supply the colour array directly.

Colours cycle through values in the order levels appear, unless limits fixes the level order.

Usage

scale-fill-manual(
  values,
  name,
  limits,
  oob,
  labels,
)

Parameters

Parameter Default Description
values Array of colours, one per level.
name Legend title. Overrides any name set via labels when both are present.
limits Array of level names controlling order and inclusion, or none.
oob Out-of-range policy: "drop" (default) removes rows whose value falls outside limits; "squish" clamps continuous values to the nearest endpoint.
labels Array of legend labels aligned with limits, or auto.

Returns

Scale object consumed by plot.

Examples

Hand-picked colour array applied to three categorical levels.

#let d = (
  (grp: "a", y: 1),
  (grp: "b", y: 2),
  (grp: "c", y: 3),
)
#plot(
  data: d,
  mapping: aes(x: "grp", y: "y", fill: "grp"),
  layers: (geom-col(),),
  scales: (scale-fill-manual(values: (
    rgb("#66c2a5"), rgb("#fc8d62"), rgb("#8da0cb"),
  )),),
  width: 10cm,
  height: 6cm,
)

Bar chart of three bars a, b, c filled with a hand-picked sea-green, salmon, and lavender trio supplied via the manual values cycle.

Bar chart of three bars a, b, c filled with a hand-picked sea-green, salmon, and lavender trio supplied via the manual values cycle.

The same array shown as a swatch strip via geom-rect.

#let pal = (rgb("#66c2a5"), rgb("#fc8d62"), rgb("#8da0cb"))
#let d = pal.enumerate().map(((i, _)) => (
  xmin: i, xmax: i + 1, ymin: 0, ymax: 1, k: str(i),
))
#plot(
  data: d,
  mapping: aes(xmin: "xmin", xmax: "xmax", ymin: "ymin", ymax: "ymax", fill: "k"),
  layers: (geom-rect(),),
  scales: (scale-fill-manual(values: pal),),
  guides: guides(fill: none),
  theme: theme-void(),
  width: 6cm,
  height: 1cm,
)

Legend swatch strip of three rectangles displaying the hand-picked sea-green, salmon, and lavender fill colours in order.

Legend swatch strip of three rectangles displaying the hand-picked sea-green, salmon, and lavender fill colours in order.

See also

scale-fill-discrete, scale-colour-manual.

Back to top