stat-summary-2d
Two-dimensional summary statistic.
Partitions (x, y) into a rectangular grid (same rule as @stat-bin-2d), then for every non-empty cell reduces the z values inside to a single scalar emitted as the _value column.
fun accepts a string keyword ("mean", "median", "sum", "min", "max") or a callable values => scalar.
Usage
stat-summary-2d(
fun: "mean",
bins: 30,
binwidth: none,
)Parameters
| Parameter | Default | Description |
|---|---|---|
fun |
"mean" |
Reduction. String keyword or callable. |
bins |
30 |
Scalar or (x, y) pair — target bin counts. |
binwidth |
none |
Scalar or (x, y) pair — fixed bin widths. |
Returns
Statistic object with name: "summary_2d".
Outputs
x.y._value.xmin.xmax.ymin.ymax.
Examples
Reduce a z aesthetic over a 25-by-25 grid: each cell paints by the mean of the values that fell inside it.
#let n = 600
#let d = range(0, n).map(i => {
let t = i / n
let theta = t * 6 * calc.pi
let r = 1 + t * 3
let x = r * calc.cos(theta) + calc.sin(t * 11.0) * 0.3
let y = r * calc.sin(theta) + calc.cos(t * 13.0) * 0.3
(x: x, y: y, z: r)
})
#plot(
data: d,
mapping: aes(x: "x", y: "y", z: "z"),
layers: (geom-rect(stat: stat-summary-2d(fun: "mean", bins: 25)),),
scales: (scale-fill-viridis-c(),),
width: 10cm,
height: 6cm,
)