scale-colour-distiller

Continuous ColorBrewer colour scale.

Looks up a Brewer palette by name and interpolates linearly across its stops as a continuous ramp. direction flips the palette: 1 keeps the canonical order, -1 reverses it.

Usage

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

Parameters

Parameter Default Description
palette ColorBrewer palette name (sequential or diverging works best).
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.
breaks Array of break values for the legend, or auto.
labels Array of legend labels aligned with breaks, or auto.

Returns

Scale object consumed by plot.

Examples

Spectral palette interpolated as a continuous ramp.

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

Scatter chart of twelve diagonal points coloured by z along the ColorBrewer Spectral palette lifted into a smooth continuous ramp from red through yellow to blue.

Scatter chart of twelve diagonal points coloured by z along the ColorBrewer Spectral palette lifted into a smooth continuous ramp from red through yellow to blue.

Set direction: -1 to reverse the palette so high values map to the canonical low end.

#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-distiller(palette: "Blues", direction: -1),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of twelve diagonal points coloured by z along a reversed Blues distiller ramp so high values appear pale and low values dark blue.

Scatter chart of twelve diagonal points coloured by z along a reversed Blues distiller ramp so high values appear pale and low values dark blue.

See also

scale-fill-distiller, scale-colour-gradientn, scale-colour-brewer.

Back to top