scale-colour-gradient2

Continuous diverging colour gradient through a midpoint.

Interpolates low to mid for values at or below midpoint, and mid to high for values at or above it.

Usage

scale-colour-gradient2(
  ..args,
)

Parameters

Parameter Default Description
..args

Returns

Scale object consumed by plot.

Examples

Default diverging ramp pivoting at zero, useful for signed numeric values.

#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-gradient2(midpoint: 0),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of eleven points coloured by z along a diverging ramp that pivots through white at zero, blue for negative and red for positive.

Scatter chart of eleven points coloured by z along a diverging ramp that pivots through white at zero, blue for negative and red for positive.

Shift midpoint to centre the ramp around a non-zero baseline.

#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-gradient2(
    low: rgb("#1a9850"),
    mid: rgb("#ffffbf"),
    high: rgb("#d73027"),
    midpoint: 5,
  ),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of eleven points coloured by z along a green-yellow-red diverging ramp pivoting through pale yellow at midpoint 5.

Scatter chart of eleven points coloured by z along a green-yellow-red diverging ramp pivoting through pale yellow at midpoint 5.

See also

scale-colour-gradient, scale-colour-gradientn, scale-fill-gradient2.

Back to top