stat-sum

Sum statistic: one output row per unique (x, y) pair with _n and _prop.

Output rows preserve first-seen pair order. The stat re-maps size to the "_n" column so geoms picking up the aesthetic see counts directly.

Usage

stat-sum()

Returns

Statistic object with name: "sum", consumed by geom layers.

Outputs

  • x.
  • y.
  • _n.
  • _prop.

Examples

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

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

Scatter chart with x and y axes where marker size encodes the count of duplicate observations at each coordinate, larger at (1, 1) than at (2, 2).

Scatter chart with x and y axes where marker size encodes the count of duplicate observations at each coordinate, larger at (1, 1) than at (2, 2).

Constructor form: stat: stat-sum() is equivalent to stat: "sum" with defaults.

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

Scatter chart with x and y axes where stat-sum scales marker area with the duplicate count at each (x, y), largest at (1, 1), smaller at (3, 3), smallest at (2, 2).

Scatter chart with x and y axes where stat-sum scales marker area with the duplicate count at each (x, y), largest at (1, 1), smaller at (3, 3), smallest at (2, 2).

See also

geom-count, stat-count, stat-unique.

Back to top