stat-summary-hex
Hex-grid summary statistic.
Partitions (x, y) into a pointy-top hex grid (same rule as @stat-bin-hex), then reduces the z values inside each cell to a single scalar emitted as the _value column.
Usage
stat-summary-hex(
fun: "mean",
bins: 30,
binwidth: none,
)Parameters
| Parameter | Default | Description |
|---|---|---|
fun |
"mean" |
Reduction. String keyword ("mean", "median", "sum", "min", "max") or callable. |
bins |
30 |
Scalar or (x, y) pair — target bin counts. |
binwidth |
none |
Scalar or (x, y) pair — fixed pitches. |
Returns
Statistic object with name: "summary_hex".
Outputs
x.y._value.
Examples
Override the default hex statistic via a dictionary-merge so each cell paints by the mean z over a 25-bin grid.
#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-hex(bins: 25) + (stat: stat-summary-hex(fun: "mean", bins: 25)),
),
scales: (scale-fill-viridis-c(),),
width: 10cm,
height: 6cm,
)