geom-vline

Vertical reference line at one or more x intercepts.

xintercept can be a scalar or an array. The layer does not inherit the plot mapping by default; it draws purely from the xintercept parameter.

Usage

geom-vline(
  xintercept: none,
  colour: auto,
  stroke: 0.6pt,
  alpha: auto,
  linetype: "solid",
  inherit-aes: false,
)

Parameters

Parameter Default Description
xintercept none Scalar or array of x values at which to draw vertical lines.
colour auto Line colour. auto inherits the theme ink.
stroke 0.6pt Line thickness (a Typst length).
alpha auto Line opacity in [0, 1].
linetype "solid" Dash keyword. Defaults to "solid".
inherit-aes false Whether to merge the plot-level mapping into this layer’s mapping. Defaults to false.

Returns

Layer dictionary consumed by plot.

Examples

Two vertical reference lines at x = 3 and x = 6.

#let d = range(0, 10).map(i => (x: i, y: i * 0.5))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (
    geom-point(size: 2pt),
    geom-vline(xintercept: (3, 6), colour: rgb("#4c78a8")),
  ),
  width: 10cm,
  height: 6cm,
)

Scatter of x against y = 0.5 x over x = 0 to 9 overlaid with two blue vertical reference lines at x = 3 and 6.

Scatter of x against y = 0.5 x over x = 0 to 9 overlaid with two blue vertical reference lines at x = 3 and 6.

A single dashed reference line at the data midpoint.

#let d = range(0, 10).map(i => (x: i, y: i * 0.5))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (
    geom-point(size: 2pt),
    geom-vline(xintercept: 4.5, stroke: 1pt, colour: rgb("#cc0000")),
  ),
  width: 10cm,
  height: 6cm,
)

Scatter of x against y = 0.5 x over x = 0 to 9 overlaid with a single red vertical reference line at x = 4.5.

Scatter of x against y = 0.5 x over x = 0 to 9 overlaid with a single red vertical reference line at x = 4.5.

See also

geom-hline, geom-abline.

Back to top