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,
  breaks: auto,
  range: (0.1, 1),
  name: none,
  limits: none,
  oob: "drop",
  labels: auto,
)

Parameters

Parameter Default Description
n-breaks 4 Number of legend bins. Ignored when breaks is set.
breaks auto Array of bin edges for the legend, or auto to derive equal-width bins from n-breaks. Affects the legend only; the per-row mapping stays continuous.
range (0.1, 1) Pair (min, max) bounding the output opacity in [0, 1].
name none Legend title. Overrides any name set via labels when both are present.
limits none Pair (lo, hi) clipping the trained domain, or none.
oob "drop" Out-of-range policy: "drop" (default) removes rows whose value falls outside limits; "squish" clamps continuous values to the nearest endpoint.
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