stat-bin-hex

Two-dimensional hexagonal bin statistic: partition (x, y) into a pointy-top hex grid and count rows per cell.

bins and binwidth accept either a scalar or an (x, y) pair.

Usage

stat-bin-hex(
  bins: 30,
  binwidth: none,
)

Parameters

Parameter Default Description
bins 30 Scalar or (x, y) pair — target bin counts.
binwidth none Scalar or (x, y) pair — fixed pitches.

Returns

Statistic object with name: "bin_hex".

Outputs

  • x.
  • y.
  • _count.
  • _density.

Examples

stat-bin-hex powers geom-hex; pass bins (or binwidth) through the wrapper to bin a noisy scatter onto a 20-bin hex grid coloured by count.

#let d = range(0, 400).map(i => (
  x: calc.sin(i * 0.13) * 4,
  y: calc.cos(i * 0.21) * 4,
))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-hex(bins: 20),),
  scales: (scale-fill-viridis-c(),),
  width: 10cm,
  height: 6cm,
)

Hexagonal bin grid of sine/cosine samples with 20 hex cells per axis shaded by count via geom-hex backed by stat-bin-hex and the viridis fill palette.

Hexagonal bin grid of sine/cosine samples with 20 hex cells per axis shaded by count via geom-hex backed by stat-bin-hex and the viridis fill palette.

See also

geom-hex, stat-bin-2d.

Back to top