scale-linewidth-continuous

Continuous linewidth scale mapping a numeric column to stroke thickness.

Usage

scale-linewidth-continuous(
  name: none,
  range: (0.4pt, 1.4pt),
  limits: none,
  oob: "drop",
  breaks: auto,
  labels: auto,
)

Parameters

Parameter Default Description
name none Legend title. Overrides any name set via labels when both are present.
range (0.4pt, 1.4pt) Pair of Typst lengths (min, max) bounding the output thickness.
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.
breaks auto Array of break values for the legend, or auto.
labels auto Array of legend labels aligned with breaks, or auto.

Returns

Scale object consumed by plot.

Examples

Linewidth grows with w, one line per group.

#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-continuous(range: (0.4pt, 2pt)),),
  width: 10cm,
  height: 6cm,
)

Line chart of four diagonal lines whose stroke thickness scales continuously with w from thin to thick.

Line chart of four diagonal lines whose stroke thickness scales continuously with w from thin to thick.

Pair colour and linewidth with the same column to encode magnitude through both channels.

#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", colour: "w", linewidth: "w", group: "g"),
  layers: (geom-line(),),
  scales: (scale-linewidth-continuous(range: (0.4pt, 3pt)),),
  width: 10cm,
  height: 6cm,
)

Line chart of four diagonal lines where w encodes both stroke thickness and colour so magnitude grows redundantly through both channels.

Line chart of four diagonal lines where w encodes both stroke thickness and colour so magnitude grows redundantly through both channels.

See also

scale-linewidth-identity, scale-size-continuous.

Back to top