geom-boxplot
Boxplot layer: draws a Tukey box, whiskers, and outlier points per group.
Defaults to stat = "boxplot", so the layer accepts raw observations and computes the five-number summary per group internally. The default position = "identity" keeps groups at their categorical x slot; switch to "dodge" if you want side-by-side boxes per fill level.
Usage
geom-boxplot(
mapping: none,
data: none,
width: 0.6,
colour: auto,
fill: auto,
stroke: 0.6pt,
alpha: auto,
outlier-size: 1.8pt,
outlier-colour: auto,
whisker-cap: 0.5,
stat: "boxplot",
position: "identity",
inherit-aes: true,
)Parameters
| Parameter | Default | Description |
|---|---|---|
mapping |
none |
Layer-specific aesthetic mapping built with aes. Falls back to the plot mapping when none. |
data |
none |
Layer-specific dataset. Falls back to the plot data when none. |
width |
0.6 |
Box width in x data units. For discrete x this is also a data-unit width. |
colour |
auto |
Stroke colour for the box, median, and whiskers. auto falls back to the theme ink only when neither colour nor fill is set. |
fill |
auto |
Box fill colour. auto resolves via the fill scale or a neutral default. |
stroke |
0.6pt |
Stroke thickness for the box outline and whiskers. |
alpha |
auto |
Box opacity in [0, 1]. |
outlier-size |
1.8pt |
Marker size for outlier points. |
outlier-colour |
auto |
Marker colour for outlier points. auto follows the box stroke colour. |
whisker-cap |
0.5 |
Cap length at the whisker ends as a fraction of width. |
stat |
"boxplot" |
Statistical transform name. "boxplot" by default. |
position |
"identity" |
Position adjustment name. "identity" by default. |
inherit-aes |
true |
Whether to merge the plot-level mapping into this layer’s mapping. |
Returns
Layer dictionary consumed by plot.
Examples
Five-number summary computed per category from raw observations.
#let d = ()
#for grp in ("a", "b", "c") {
for i in range(20) {
d.push((grp: grp, y: calc.sin(i) + i / 10))
}
}
#plot(
data: d,
mapping: aes(x: "grp", y: "y"),
layers: (geom-boxplot(),),
width: 10cm,
height: 6cm,
)Add a second mapping (fill) and switch position to "dodge" to compare distributions side by side per group.
#let d = ()
#for grp in ("a", "b", "c") {
for k in ("x", "y") {
for i in range(20) {
d.push((grp: grp, k: k, y: calc.sin(i) + i / 10 + (if k == "y" { 0.7 } else { 0 })))
}
}
}
#plot(
data: d,
mapping: aes(x: "grp", y: "y", fill: "k"),
layers: (geom-boxplot(position: "dodge"),),
width: 10cm,
height: 6cm,
)