scale-colour-brewer

Discrete ColorBrewer colour scale.

palette selects a named ColorBrewer palette such as "Set1", "Dark2", or "Spectral". Categorical levels are mapped to colours in the order they first appear in the data.

Usage

scale-colour-brewer(
  ..args,
)

Parameters

Parameter Default Description
..args

Returns

Scale object consumed by plot.

Examples

Set1 palette mapping three categorical levels to bold qualitative hues.

#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-brewer(palette: "Set1"),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of three points where sp maps to bold qualitative red, blue, and green hues sampled from the ColorBrewer Set1 palette.

Scatter chart of three points where sp maps to bold qualitative red, blue, and green hues sampled from the ColorBrewer Set1 palette.

Switching to the diverging Spectral palette suits ordered categories with a meaningful midpoint.

#let d = (
  (x: 1, y: 2, sp: "low"),
  (x: 2, y: 3, sp: "mid"),
  (x: 3, y: 4, sp: "high"),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", colour: "sp"),
  layers: (geom-point(size: 3pt),),
  scales: (scale-colour-brewer(
    palette: "Spectral",
    limits: ("low", "mid", "high"),
  ),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of three points where ordered categories low, mid, high map to colours from the diverging Spectral palette running red through yellow to blue.

Scatter chart of three points where ordered categories low, mid, high map to colours from the diverging Spectral palette running red through yellow to blue.

See also

scale-fill-brewer, scale-colour-discrete.

Back to top