scale-colour-fermenter

Binned ColorBrewer colour scale.

Looks up a Brewer palette by name, interpolates across its stops, and quantises the lookup into n-breaks equal-width bins. direction flips the palette: 1 keeps the canonical order, -1 reverses it.

Usage

scale-colour-fermenter(
  palette,
  n-breaks,
  breaks,
  direction,
  name,
  limits,
  oob,
  labels,
)

Parameters

Parameter Default Description
palette ColorBrewer palette name (sequential or diverging works best).
n-breaks Number of bins to partition the domain into. Ignored when breaks is set.
breaks Array of bin edges, or auto to derive equal-width bins from n-breaks. Edges define the bin boundaries; n-breaks is ignored when set.
direction 1 for canonical order, -1 for reversed.
name Legend title. Overrides any name set via labels when both are present.
limits Pair (lo, hi) clipping the trained domain, 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 the bins, or auto.

Returns

Scale object consumed by plot.

Examples

Spectral palette quantised into five bins.

#let d = range(0, 12).map(i => (x: i, y: i, z: i * 0.5))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", colour: "z"),
  layers: (geom-point(size: 3pt),),
  scales: (scale-colour-fermenter(palette: "Spectral", n-breaks: 5),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of twelve diagonal points where z is cut into five stepped bands along the ColorBrewer Spectral palette running red through yellow to blue.

Scatter chart of twelve diagonal points where z is cut into five stepped bands along the ColorBrewer Spectral palette running red through yellow to blue.

Sequential blues palette reversed via direction: -1 for an inverted banding.

#let d = range(0, 12).map(i => (x: i, y: i, z: i * 0.5))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", colour: "z"),
  layers: (geom-point(size: 3pt),),
  scales: (scale-colour-fermenter(
    palette: "Blues",
    direction: -1,
    n-breaks: 7,
  ),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of twelve diagonal points where z is cut into seven stepped bands along a reversed Blues fermenter palette so high values appear pale and low dark blue.

Scatter chart of twelve diagonal points where z is cut into seven stepped bands along a reversed Blues fermenter palette so high values appear pale and low dark blue.

See also

scale-colour-distiller, scale-fill-fermenter.

Back to top