geom-count

Count layer drawing one marker per unique (x, y), sized by frequency.

Usage

geom-count(
  mapping: none,
  data: none,
  size: 3pt,
  stroke: none,
  fill: auto,
  colour: auto,
  alpha: auto,
  shape: auto,
  stat: "sum",
  position: "identity",
  inherit-aes: true,
)

Parameters

Parameter Default Description
mapping none Layer-specific aesthetic mapping built with aes. Falls back to the plot mapping when none.
data none Layer-specific dataset. Falls back to the plot data when none.
size 3pt Marker size (a Typst length). Used as the fixed size when no size scale is active.
stroke none Marker stroke; none means no outline.
fill auto Marker fill colour. auto resolves via the colour scale or a neutral default.
colour auto Fixed marker outline colour. auto resolves via the colour scale, falling back to the theme ink. Only takes effect when stroke is non-zero.
alpha auto Marker opacity in [0, 1].
shape auto Marker shape keyword. auto honours the shape scale.
stat "sum" Statistical transform name. Defaults to "sum".
position "identity" Position adjustment name. Usually "identity".
inherit-aes true Whether to merge the plot-level mapping into this layer’s mapping.

Returns

Layer dictionary consumed by plot.

Examples

Marker size grows with the number of duplicate (x, y) rows.

#let d = (
  (x: 1, y: 1),
  (x: 1, y: 1),
  (x: 2, y: 2),
  (x: 3, y: 3),
  (x: 3, y: 3),
  (x: 3, y: 3),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-count(),),
  width: 10cm,
  height: 6cm,
)

Scatter of x against y where each marker size encodes the number of duplicate (x, y) rows at that location.

Scatter of x against y where each marker size encodes the number of duplicate (x, y) rows at that location.

Pair with scale-size-area to give markers an area-proportional scaling (instead of a radius-proportional one).

#let d = (
  (x: 1, y: 1),
  (x: 1, y: 1),
  (x: 2, y: 2),
  (x: 3, y: 3),
  (x: 3, y: 3),
  (x: 3, y: 3),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-count(),),
  scales: (scale-size-area(range: (1pt, 12pt)),),
  width: 10cm,
  height: 6cm,
)

Scatter of x against y with marker size proportional to area encoding count of duplicate (x, y) rows.

Scatter of x against y with marker size proportional to area encoding count of duplicate (x, y) rows.

See also

geom-point, stat-sum.

Back to top