geom-hex

Hex bin layer: counts (x, y) into a pointy-top hex grid and draws one hexagon per non-empty cell. Default fill encodes count via the fill scale.

Usage

geom-hex(
  mapping: none,
  data: none,
  bins: 30,
  binwidth: none,
  colour: auto,
  fill: auto,
  stroke: none,
  alpha: auto,
  inherit-aes: true,
)

Parameters

Parameter Default Description
mapping none Layer-specific aesthetic mapping built with aes. Must map x and y.
data none Layer-specific dataset. Falls back to the plot data when none.
bins 30 Scalar or (x, y) pair — target bin counts.
binwidth none Scalar or (x, y) pair — fixed pitches.
colour auto Cell outline colour.
fill auto Cell fill colour. auto lets the fill scale paint by _count.
stroke none Outline thickness or stroke dictionary.
alpha auto Cell opacity in [0, 1].
inherit-aes true Whether to merge the plot-level mapping into this layer’s mapping.

Returns

Layer dictionary consumed by plot.

Examples

25-bin pointy-top hex grid coloured by count.

#let n = 600
#let d = range(0, n).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: 25),),
  scales: (scale-fill-viridis-c(option: "magma"),),
  width: 10cm,
  height: 6cm,
)

Hexagonal bin grid of 600 sine/cosine samples with pointy-top cells shaded by count via the magma palette.

Hexagonal bin grid of 600 sine/cosine samples with pointy-top cells shaded by count via the magma palette.

See also

geom-bin-2d, stat-bin-hex.

Back to top