scale-alpha-binned

Binned continuous alpha scale.

Maps a numeric column onto an opacity range, but groups values into n-breaks bins for the legend. The mapping stays continuous; only the legend swatches snap to bin centres.

Usage

scale-alpha-binned(
  n-breaks: 4,
  range: (0.1, 1),
  name: none,
  limits: none,
  labels: auto,
)

Parameters

Parameter Default Description
n-breaks 4 Number of legend bins.
range (0.1, 1) Pair (min, max) bounding the output opacity in [0, 1].
name none Legend title. Overrides any name set via labs when both are present.
limits none Pair (lo, hi) clipping the trained domain, or none.
labels auto Array of legend labels aligned with breaks, or auto.

Returns

Scale object consumed by plot.

Examples

Opacity binned into four legend swatches.

#let d = range(0, 10).map(i => (x: i, y: i, w: i + 1))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", alpha: "w"),
  layers: (geom-point(size: 4pt, fill: rgb("#1f77b4")),),
  scales: (scale-alpha-binned(n-breaks: 4, range: (0.2, 1)),),
  width: 10cm,
  height: 6cm,
)

Scatter chart of ten blue diagonal points where w drives opacity along a continuous mapping but the legend collapses into four stepped opacity swatches.

Scatter chart of ten blue diagonal points where w drives opacity along a continuous mapping but the legend collapses into four stepped opacity swatches.

See also

scale-alpha-continuous, scale-linewidth-binned.

Back to top