scale-colour-steps2

Binned diverging colour gradient through a midpoint.

Quantises the trained continuous domain into n-breaks equal-width bins using a three-stop palette that pivots through mid at midpoint.

Usage

scale-colour-steps2(
  low,
  mid,
  high,
  midpoint,
  n-breaks,
  breaks,
  name,
  limits,
  oob,
  labels,
)

Parameters

Parameter Default Description
low Colour for values far below midpoint.
mid Colour at midpoint.
high Colour for values far above midpoint.
midpoint Value at which the palette transitions through mid.
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

Six-bin diverging discretisation pivoting at zero.

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

Scatter chart of eleven points where z is cut into six stepped bands along a diverging ramp that pivots through white at zero, green for negative and red for positive.

Scatter chart of eleven points where z is cut into six stepped bands along a diverging ramp that pivots through white at zero, green for negative and red for positive.

Shift midpoint and adjust the three stops to highlight a non-zero pivot.

#let d = range(0, 11).map(i => (x: i, y: i, z: i))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", colour: "z"),
  layers: (geom-point(size: 3pt),),
  scales: (scale-colour-steps2(
    low: rgb("#1a9850"),
    mid: rgb("#ffffbf"),
    high: rgb("#d73027"),
    midpoint: 5,
    n-breaks: 8,
  ),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of eleven points where z is cut into eight stepped bands along a green-yellow-red diverging ramp pivoting through pale yellow at midpoint 5.

Scatter chart of eleven points where z is cut into eight stepped bands along a green-yellow-red diverging ramp pivoting through pale yellow at midpoint 5.

See also

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

Back to top