geom-hline

Horizontal reference line at one or more y intercepts.

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

Usage

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

Parameters

Parameter Default Description
yintercept none Scalar or array of y values at which to draw horizontal 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

Single horizontal reference line at y = 5.

#let d = range(0, 10).map(i => (x: i, y: i + 2))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (
    geom-point(size: 2pt),
    geom-hline(yintercept: 5, colour: rgb("#cc0000")),
  ),
  width: 10cm,
  height: 6cm,
)

Scatter of x against y = x + 2 overlaid with a red horizontal reference line at y = 5.

Scatter of x against y = x + 2 overlaid with a red horizontal reference line at y = 5.

Pass an array of intercepts to draw several reference lines at once.

#let d = range(0, 10).map(i => (x: i, y: i + 2))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (
    geom-point(size: 2pt),
    geom-hline(yintercept: (3, 6, 9), colour: rgb("#888888")),
  ),
  width: 10cm,
  height: 6cm,
)

Scatter of x against y = x + 2 overlaid with three grey horizontal reference lines at y = 3, 6 and 9.

Scatter of x against y = x + 2 overlaid with three grey horizontal reference lines at y = 3, 6 and 9.

See also

geom-vline, geom-abline.

Back to top