scale-linewidth-binned

Binned continuous linewidth scale.

Maps a numeric column onto a stroke-thickness range, but groups values into n-breaks bins for the legend. The mapping stays continuous so drawn strokes vary smoothly within each bin; only the legend swatches snap to bin centres.

Usage

scale-linewidth-binned(
  n-breaks: 4,
  breaks: auto,
  range: (0.4pt, 1.4pt),
  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.4pt, 1.4pt) Pair of Typst lengths (min, max) bounding the output thickness.
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

Linewidth grows with w, with the legend grouped into four bins.

#let d = (
  (x: 1, y: 1, w: 1, g: "a"), (x: 2, y: 2, w: 1, g: "a"),
  (x: 3, y: 3, w: 1, g: "a"), (x: 4, y: 4, w: 1, g: "a"),
  (x: 1, y: 2, w: 4, g: "b"), (x: 2, y: 3, w: 4, g: "b"),
  (x: 3, y: 4, w: 4, g: "b"), (x: 4, y: 5, w: 4, g: "b"),
  (x: 1, y: 3, w: 7, g: "c"), (x: 2, y: 4, w: 7, g: "c"),
  (x: 3, y: 5, w: 7, g: "c"), (x: 4, y: 6, w: 7, g: "c"),
  (x: 1, y: 4, w: 10, g: "d"), (x: 2, y: 5, w: 10, g: "d"),
  (x: 3, y: 6, w: 10, g: "d"), (x: 4, y: 7, w: 10, g: "d"),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", linewidth: "w", group: "g"),
  layers: (geom-line(),),
  scales: (scale-linewidth-binned(n-breaks: 4, range: (0.4pt, 2pt)),),
  width: 10cm,
  height: 6cm,
)

Line chart of four diagonal lines whose strokes thicken with w while the legend collapses into four stepped thickness bins.

Line chart of four diagonal lines whose strokes thicken with w while the legend collapses into four stepped thickness bins.

See also

scale-linewidth-continuous, scale-size-binned.

Back to top