scale-colour-stepsn

Binned n-stop colour gradient.

Walks colours as a sequence of stops and quantises the lookup into n-breaks equal-width bins.

Usage

scale-colour-stepsn(
  colours,
  n-breaks,
  breaks,
  name,
  limits,
  oob,
  labels,
)

Parameters

Parameter Default Description
colours Array of two or more colours.
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.
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

Three-stop ramp discretised into six 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-stepsn(colours: (
    rgb("#1a9850"), rgb("#ffffbf"), rgb("#d73027"),
  ), n-breaks: 6),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of twelve diagonal points where z is cut into six stepped bands along a custom three-stop n-stop ramp passing green through pale yellow to red.

Scatter chart of twelve diagonal points where z is cut into six stepped bands along a custom three-stop n-stop ramp passing green through pale yellow to red.

Reuse a brewer palette as the stop list to fold a discrete palette into a banded continuous scale.

#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-stepsn(
    colours: brewer-palette("YlOrRd"),
    n-breaks: 5,
  ),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of twelve diagonal points where z is cut into five stepped bands along the ColorBrewer YlOrRd palette fed as the n-stop list.

Scatter chart of twelve diagonal points where z is cut into five stepped bands along the ColorBrewer YlOrRd palette fed as the n-stop list.

See also

scale-colour-steps, scale-colour-steps2, scale-fill-stepsn.

Back to top