scale-colour-manual

Manual discrete colour scale: supply the colour array directly.

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

Usage

scale-colour-manual(
  ..args,
)

Parameters

Parameter Default Description
..args

Returns

Scale object consumed by plot.

Examples

Hand-picked colour array applied to three categorical levels.

#let d = (
  (x: 1, y: 2, sp: "a"),
  (x: 2, y: 4, sp: "b"),
  (x: 3, y: 3, sp: "c"),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", colour: "sp"),
  layers: (geom-point(size: 3pt),),
  scales: (scale-colour-manual(values: (
    rgb("#1b9e77"), rgb("#d95f02"), rgb("#7570b3"),
  )),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of three points where sp maps to a hand-picked teal, orange, and blue trio supplied via the manual values cycle.

Scatter chart of three points where sp maps to a hand-picked teal, orange, and blue trio supplied via the manual values cycle.

limits fixes the level order independently of how rows appear in the data, useful for stable legends across datasets.

#let d = (
  (x: 1, y: 2, sp: "c"),
  (x: 2, y: 4, sp: "a"),
  (x: 3, y: 3, sp: "b"),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", colour: "sp"),
  layers: (geom-point(size: 3pt),),
  scales: (scale-colour-manual(
    values: (rgb("#1b9e77"), rgb("#d95f02"), rgb("#7570b3")),
    limits: ("a", "b", "c"),
  ),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of three points where limits forces a, b, c order so the teal, orange, blue manual cycle stays stable regardless of input order.

Scatter chart of three points where limits forces a, b, c order so the teal, orange, blue manual cycle stays stable regardless of input order.

See also

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

Back to top