geom-abline
Straight reference line described by slope and intercept.
The line runs across the full trained x domain. Requires continuous x and y scales; discrete scales are skipped silently.
Usage
geom-abline(
slope: 1,
intercept: 0,
colour: auto,
stroke: 0.6pt,
alpha: auto,
linetype: "solid",
inherit-aes: false,
)Parameters
| Parameter | Default | Description |
|---|---|---|
slope |
1 |
Line slope. |
intercept |
0 |
Line y intercept. |
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
The y = x identity reference line over a noisy point cloud.
#let d = range(0, 10).map(i => (x: i, y: i + calc.rem(i, 2)))
#plot(
data: d,
mapping: aes(x: "x", y: "y"),
layers: (
geom-point(size: 2pt),
geom-abline(slope: 1, intercept: 0, colour: rgb("#cc0000")),
),
width: 10cm,
height: 6cm,
)Adjust slope and intercept to anchor a custom regression reference.
#let d = range(0, 10).map(i => (x: i, y: 0.7 * i + 1 + calc.sin(i)))
#plot(
data: d,
mapping: aes(x: "x", y: "y"),
layers: (
geom-point(size: 2pt),
geom-abline(slope: 0.7, intercept: 1, colour: rgb("#1b9e77")),
),
width: 10cm,
height: 6cm,
)