scale-linetype-binned

Binned linetype scale: cuts a continuous variable into n-breaks bins, each bin gets one dash keyword from palette.

The scale stays continuous: the trained domain is numeric and the resolver snaps each row to the bin its value falls into.

Usage

scale-linetype-binned(
  n-breaks: 4,
  breaks: auto,
  palette: auto,
  name: none,
  limits: none,
  oob: "drop",
  labels: auto,
)

Parameters

Parameter Default Description
n-breaks 4 Number of bins to partition the continuous domain into. Ignored when breaks is set.
breaks auto Array of bin edges, or auto to derive equal-width bins from n-breaks. Edges define the bin boundaries; n-breaks is ignored when set.
palette auto Array of dash keywords, one per bin, or auto for the library default.
name none Legend title. Overrides any name set via labels when both are present.
limits none Continuous (lo, hi) pair pinning the 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 bin midpoints, or auto.

Returns

Scale object consumed by plot.

Examples

Bin a continuous quality column into three linetype buckets.

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

Line chart of four diagonal lines where the continuous q column is cut into three stepped dash-pattern bands, with the two highest groups collapsing onto the same dash.

Line chart of four diagonal lines where the continuous q column is cut into three stepped dash-pattern bands, with the two highest groups collapsing onto the same dash.

See also

scale-linetype, scale-linetype-manual, geom-line.

Back to top