scale-fill-gradient2

Continuous diverging fill gradient through a midpoint.

Fill counterpart of scale-colour-gradient2.

Usage

scale-fill-gradient2(
  low,
  mid,
  high,
  midpoint,
  name,
  limits,
  oob,
  breaks,
  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.
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

Diverging ramp pivoting at zero, shown as a swatch via geom-rect.

#let d = range(-7, 8).map(i => (
  xmin: i, xmax: i + 1, ymin: 0, ymax: 1, z: i,
))
#plot(
  data: d,
  mapping: aes(xmin: "xmin", xmax: "xmax", ymin: "ymin", ymax: "ymax", fill: "z"),
  layers: (geom-rect(),),
  scales: (scale-fill-gradient2(midpoint: 0),),
  guides: guides(fill: none),
  theme: theme-void(),
  width: 10cm,
  height: 1cm,
)

Colour-bar swatch of fifteen rectangles displaying a diverging fill gradient that pivots through white at zero, blue for negative and red for positive.

Colour-bar swatch of fifteen rectangles displaying a diverging fill gradient that pivots through white at zero, blue for negative and red for positive.

See also

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

Back to top