geom-density-ridges
Ridgeline layer: overlapping filled density curves of x per y bucket.
Mapping must provide x and y. The scale parameter sets the tallest ridge’s height in y-level units: 1 makes it exactly reach the next bucket’s baseline, larger values overlap it.
Usage
geom-density-ridges(
mapping: none,
data: none,
scale: 1.8,
bw: auto,
adjust: 1,
n: 512,
trim: false,
colour: auto,
fill: auto,
stroke: 0.6pt,
alpha: auto,
stat: auto,
position: "identity",
key: auto,
inherit-aes: true,
)Parameters
| Parameter | Default | Description |
|---|---|---|
mapping |
none |
Layer-specific aesthetic mapping built with aes. Must map x and y. |
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. |
scale |
1.8 |
Tallest ridge height in y-level units; values above 1 overlap the ridge behind. |
bw |
auto |
Kernel bandwidth. auto applies Silverman’s rule of thumb; pass a positive number to fix it. |
adjust |
1 |
Bandwidth multiplier: adjust: 0.5 halves the smoothing, adjust: 2 doubles it. |
n |
512 |
Number of evenly spaced grid points the density is evaluated at per bucket. |
trim |
false |
Whether to restrict each ridge to its bucket’s x range instead of letting it decay to the baseline. |
colour |
auto |
Fixed outline colour. auto resolves via the colour scale, falling back to the theme ink. |
fill |
auto |
Fixed ridge fill. auto resolves via the fill scale, falling back to the theme paper. |
stroke |
0.6pt |
Outline thickness (a Typst length) or stroke dictionary; none disables the outline. |
alpha |
auto |
Fill opacity in [0, 1]. |
stat |
auto |
Statistical transform. auto builds stat-density-ridges from the parameters above; pass a stat name or stat object to override. |
position |
"identity" |
Position adjustment name. Usually "identity". |
key |
auto |
Legend glyph override built with a draw-key-* helper. auto picks the default for the geom. |
inherit-aes |
true |
Whether to merge the plot-level mapping into this layer’s mapping. |
Returns
Layer dictionary consumed by plot.
Examples
Classic overlapping ridgeline plot of three shifted samples.
#let xs = (1, 2, 2, 3, 3, 3, 4, 4, 5, 7)
#let d = ()
#for (i, grp) in ("a", "b", "c").enumerate() {
for x in xs {
d.push((grp: grp, x: x * (1 + i * 0.4) + i))
}
}
#plot(
data: d,
mapping: aes(x: "x", y: "grp"),
layers: (geom-density-ridges(scale: 1.4),),
scales: scales(y: scale-discrete(expand: (auto, 45%))),
width: 10cm,
height: 6cm,
)Map fill to the bucket column to colour each ridge.
#let xs = (1, 2, 2, 3, 3, 3, 4, 4, 5, 7)
#let d = ()
#for (i, grp) in ("a", "b", "c").enumerate() {
for x in xs {
d.push((grp: grp, x: x * (1 + i * 0.4) + i))
}
}
#plot(
data: d,
mapping: aes(x: "x", y: "grp", fill: "grp"),
layers: (geom-density-ridges(scale: 1.4, alpha: 0.7),),
scales: scales(y: scale-discrete(expand: (auto, 45%))),
width: 10cm,
height: 6cm,
)