geom-segment
Segment layer: one line from (x, y) to (xend, yend) per row.
Mapping must provide x, y, xend, yend. Colour and linetype may be mapped or set as fixed layer parameters.
Usage
geom-segment(
mapping: none,
data: none,
stroke: 0.8pt,
colour: auto,
alpha: auto,
linetype: "solid",
stat: "identity",
position: "identity",
inherit-aes: true,
)Parameters
| Parameter | Default | Description |
|---|---|---|
mapping |
none |
Layer-specific aesthetic mapping built with aes. Must map x, y, xend, yend. |
data |
none |
Layer-specific dataset. Falls back to the plot data when none. |
stroke |
0.8pt |
Line thickness (a Typst length). |
colour |
auto |
Fixed line colour. auto resolves via the colour scale. |
alpha |
auto |
Line opacity in [0, 1]. |
linetype |
"solid" |
Dash keyword. Defaults to "solid". |
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
Three crossing segments specified by their two endpoints.
#let d = (
(x: 0, y: 0, xend: 4, yend: 3),
(x: 0, y: 3, xend: 4, yend: 0),
(x: 2, y: 0, xend: 2, yend: 3),
)
#plot(
data: d,
mapping: aes(x: "x", y: "y", xend: "xend", yend: "yend"),
layers: (geom-segment(stroke: 1pt),),
width: 10cm,
height: 6cm,
)Map colour and linetype to colour-coded categorical segments.
#let d = (
(x: 0, y: 0, xend: 4, yend: 3, k: "a"),
(x: 0, y: 3, xend: 4, yend: 0, k: "b"),
(x: 2, y: 0, xend: 2, yend: 3, k: "a"),
)
#plot(
data: d,
mapping: aes(x: "x", y: "y", xend: "xend", yend: "yend", colour: "k", linetype: "k"),
layers: (geom-segment(stroke: 1pt),),
width: 10cm,
height: 6cm,
)