stat-unique

Unique statistic: keep the first row per (x, y) key, drop later duplicates.

The dedup key concatenates the values referenced by mapping.x and mapping.y. Mapping is returned unchanged.

Usage

stat-unique()

Returns

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

Outputs

This stat passes input rows through unchanged.

Examples

Drop the duplicate (1, 1) row; the rendered scatter shows each pair only once.

#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-point(stat: "unique"),),
  width: 10cm,
  height: 6cm,
)

Scatter chart with x and y axes plotting two distinct points (1, 1) and (2, 2) after stat-unique drops the duplicate (1, 1) row from the input data.

Scatter chart with x and y axes plotting two distinct points (1, 1) and (2, 2) after stat-unique drops the duplicate (1, 1) row from the input data.

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

#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-point(stat: stat-unique(), size: 3pt),),
  width: 10cm,
  height: 6cm,
)

Scatter chart with x and y axes showing two distinct points (1, 1) and (2, 2), produced via the stat-unique constructor which removes duplicate rows.

Scatter chart with x and y axes showing two distinct points (1, 1) and (2, 2), produced via the stat-unique constructor which removes duplicate rows.

See also

stat-identity, stat-sum.

Back to top