geom-line

Line layer connecting observations in x order, one path per group.

Grouping is implicit: rows sharing the same discrete colour, fill, or group mapping form one path. Set group in aes to override when you need separate lines without mapping colour.

Usage

geom-line(
  mapping: none,
  data: none,
  stroke: auto,
  colour: auto,
  alpha: auto,
  linetype: auto,
  key: auto,
  stat: "identity",
  position: "identity",
  inherit-aes: true,
)

Parameters

Parameter Default Description
mapping none Layer-specific aesthetic mapping built with aes. Falls back to the plot mapping when none.
data none Layer-specific dataset, or a function applied to the plot data returning the layer frame. Falls back to the plot data when none.
stroke auto Line thickness (a Typst length).
colour auto Fixed line colour. auto resolves via the colour scale or a neutral default.
alpha auto Line opacity in [0, 1].
linetype auto Dash keyword (e.g., "solid", "dashed"). auto honours the linetype scale.
key auto Legend glyph override built with a draw-key-* helper. auto picks the default for the geom.
stat "identity" Statistical transform name. Usually "identity".
position "identity" Position adjustment name. Usually "identity".
inherit-aes true Whether to merge the plot-level mapping into this layer’s mapping.

Returns

Layer dictionary consumed by plot.

Examples

One line per group, derived implicitly from the colour mapping.

#let d = (
  (x: 1, y: 2, grp: "a"),
  (x: 2, y: 4, grp: "a"),
  (x: 3, y: 3, grp: "a"),
  (x: 1, y: 1, grp: "b"),
  (x: 2, y: 2, grp: "b"),
  (x: 3, y: 4, grp: "b"),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", colour: "grp"),
  layers: (geom-line(stroke: 1pt),),
  width: 10cm,
  height: 6cm,
)

Two polylines of y against x = 1 to 3 for groups a and b coloured by the colour aesthetic with implicit grouping.

Two polylines of y against x = 1 to 3 for groups a and b coloured by the colour aesthetic with implicit grouping.

Map linetype to the same column to give each group a distinct dash pattern in addition to colour.

#let d = (
  (x: 1, y: 2, grp: "a"),
  (x: 2, y: 4, grp: "a"),
  (x: 3, y: 3, grp: "a"),
  (x: 1, y: 1, grp: "b"),
  (x: 2, y: 2, grp: "b"),
  (x: 3, y: 4, grp: "b"),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", colour: "grp", linetype: "grp"),
  layers: (geom-line(stroke: 1pt),),
  width: 10cm,
  height: 6cm,
)

Two polylines of y against x = 1 to 3 for groups a and b with distinct colour and dash patterns per group.

Two polylines of y against x = 1 to 3 for groups a and b with distinct colour and dash patterns per group.

See also

geom-point, geom-smooth, scale-linetype, aes.

Back to top