stat-summary

Per-axis reduction to a central value and an uncertainty band.

The output shape is controlled by axis:

fun accepts a string name dispatched through summarise ("mean-se", "mean-cl-normal", "mean-cl-boot", "mean-sd", "median-hilow", "mean", "median", "quantile", "quantiles") or a Typst callable of the form (values, ..fun-args) -> (y, ymin, ymax).

Usage

stat-summary(
  fun: "mean-se",
  fun-args: (:),
  axis: "both",
)

Parameters

Parameter Default Description
fun "mean-se" Summary helper name or callable returning (y, ymin, ymax).
fun-args (:) Keyword arguments forwarded to the helper or callable, for example (multiplier: 2) for mean-se or (conf: 0.5) for median-hilow.
axis "both" Output axis: "both" (default), "x", or "y".

Returns

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

Outputs

  • x.
  • y.
  • xmin.
  • xmax.
  • ymin.
  • ymax.

Examples

Mean and standard-error summary per group, drawn as a line and ribbon stack.

#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-line(stat: stat-summary(fun: "mean-se")),
    geom-ribbon(stat: stat-summary(fun: "mean-se")),
  ),
  width: 10cm,
  height: 6cm,
)

Line chart with group on the x-axis and y on the y-axis, plotting the per-group mean as a line with a standard-error ribbon around it for groups a, b, c.

Line chart with group on the x-axis and y on the y-axis, plotting the per-group mean as a line with a standard-error ribbon around it for groups a, b, c.

stat: "summary" is equivalent to stat: stat-summary() with defaults (fun: "mean-se"). Use the constructor to choose a different reducer or pass fun-args.

#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-pointrange(
      size: 3pt,
      stat: stat-summary(fun: "median-hilow", fun-args: (conf: 0.5)),
    ),
  ),
  width: 10cm,
  height: 6cm,
)

Pointrange chart with group on the x-axis and y on the y-axis, showing the per-group median as a point flanked by a 50 percent hilow interval for groups a, b, c.

Pointrange chart with group on the x-axis and y on the y-axis, showing the per-group median as a point flanked by a 50 percent hilow interval for groups a, b, c.

See also

stat-summary-bin, stat-boxplot.

Back to top