stat-boxplot

Boxplot statistic: per-x five-number summary with outlier list.

One output row per distinct x value with keys (x, lower, middle, upper, ymin, ymax, outliers). lower, middle, and upper are the quartiles of the input y values; ymin and ymax are the smallest and largest y still inside the 1.5 × IQR fence; values outside the fence land in outliers.

Usage

stat-boxplot(
  coefficient: 1.5,
)

Parameters

Parameter Default Description
coefficient 1.5 Whisker length as a multiple of the inter-quartile range.

Returns

Statistic object with name: "boxplot", consumed by geom layers.

Outputs

  • x.
  • lower.
  • middle.
  • upper.
  • ymin.
  • ymax.
  • whisker-lo.
  • whisker-hi.
  • outliers.

Examples

Default 1.5 × IQR whisker rule on grouped raw observations.

#let ys = (1, 2, 3, 4, 5, 6, 7, 8, 9, 13)
#let d = ()
#for grp in ("a", "b", "c") {
  for y in ys {
    d.push((grp: grp, y: y))
  }
}
#plot(
  data: d,
  mapping: aes(x: "grp", y: "y"),
  layers: (geom-boxplot(),),
  width: 10cm,
  height: 6cm,
)

Boxplot per group on the x-axis with values on the y-axis, where the 1.5 times IQR whisker reaches the high value so no outlier is drawn for groups a, b, c.

Boxplot per group on the x-axis with values on the y-axis, where the 1.5 times IQR whisker reaches the high value so no outlier is drawn for groups a, b, c.

stat: "boxplot" is equivalent to stat: stat-boxplot() with the default coefficient: 1.5. Use the constructor to customise the whisker length, e.g., stat: stat-boxplot(coefficient: 1.0) tightens the fence so more values surface as outliers.

#let ys = (1, 2, 3, 4, 5, 6, 7, 8, 9, 13)
#let d = ()
#for grp in ("a", "b", "c") {
  for y in ys {
    d.push((grp: grp, y: y))
  }
}
#plot(
  data: d,
  mapping: aes(x: "grp", y: "y"),
  layers: (geom-boxplot(stat: stat-boxplot(coefficient: 1.0)),),
  width: 10cm,
  height: 6cm,
)

Boxplot per group on the x-axis with values on the y-axis, where a tighter 1.0 times IQR whisker rule draws the high value as an outlier above a shorter whisker for groups a, b, c.

Boxplot per group on the x-axis with values on the y-axis, where a tighter 1.0 times IQR whisker rule draws the high value as an outlier above a shorter whisker for groups a, b, c.

See also

geom-boxplot, stat-identity.

Back to top