scale-colour-steps

Binned two-stop colour gradient.

Quantises the trained continuous domain into n-breaks equal-width bins and fills each bin with a single colour drawn from the low to high ramp. Defaults to a blue ramp.

Usage

scale-colour-steps(
  low,
  high,
  n-breaks,
  breaks,
  name,
  limits,
  oob,
  labels,
)

Parameters

Parameter Default Description
low Colour for the low end of the domain.
high Colour for the high end of the domain.
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

Five-bin discretisation of the default low-to-high blue ramp.

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

Scatter chart of twelve diagonal points where z is cut into five stepped bands along the default two-stop blue ramp from dark navy to light sky-blue.

Scatter chart of twelve diagonal points where z is cut into five stepped bands along the default two-stop blue ramp from dark navy to light sky-blue.

Custom low/high colours discretised into eight bins.

#let d = range(0, 12).map(i => (x: i, y: i, z: i * 1.0))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", colour: "z"),
  layers: (geom-point(size: 3pt),),
  scales: (scale-colour-steps(
    low: rgb("#fee5d9"),
    high: rgb("#a50f15"),
    n-breaks: 8,
  ),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of twelve diagonal points where z is cut into eight stepped bands along a custom two-stop ramp from pale peach to deep crimson.

Scatter chart of twelve diagonal points where z is cut into eight stepped bands along a custom two-stop ramp from pale peach to deep crimson.

See also

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

Back to top