geom-freqpoly

Frequency polygon: a line through per-bin counts of the x aesthetic.

Usage

geom-freqpoly(
  mapping: none,
  data: none,
  bins: 30,
  binwidth: none,
  stroke: 0.8pt,
  colour: auto,
  alpha: auto,
  linetype: auto,
  position: "identity",
  inherit-aes: true,
)

Parameters

Parameter Default Description
mapping none Layer-specific aesthetic mapping built with aes. Must map x.
data none Layer-specific dataset. Falls back to the plot data when none.
bins 30 Target number of bins when binwidth is none.
binwidth none Fixed bin width. Overrides bins when set.
stroke 0.8pt Line thickness (a Typst length).
colour auto Fixed line colour. auto resolves via the colour scale.
alpha auto Line opacity in [0, 1].
linetype auto Dash keyword. auto honours the linetype scale.
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

Twelve-bin frequency polygon over a noisy series.

#let d = range(0, 40).map(i => (
  x: calc.sin(i * 0.3) * 5 + i * 0.2,
))
#plot(
  data: d,
  mapping: aes(x: "x"),
  layers: (geom-freqpoly(bins: 12, stroke: 1pt),),
  width: 10cm,
  height: 6cm,
)

Frequency polygon with 12 bins along x connecting bin counts of 40 noisy observations as a polyline.

Frequency polygon with 12 bins along x connecting bin counts of 40 noisy observations as a polyline.

Map colour to overlay frequency polygons per group on the same axes.

#let d = ()
#for grp in ("a", "b") {
  for i in range(0, 40) {
    d.push((x: calc.sin(i * 0.3) * 5 + i * 0.2 + (if grp == "b" { 2 } else { 0 }), grp: grp))
  }
}
#plot(
  data: d,
  mapping: aes(x: "x", colour: "grp"),
  layers: (geom-freqpoly(bins: 12, stroke: 1pt),),
  width: 10cm,
  height: 6cm,
)

Two overlaid frequency polygons of x with 12 bins coloured by group (a, b) via the colour aesthetic.

Two overlaid frequency polygons of x with 12 bins coloured by group (a, b) via the colour aesthetic.

See also

geom-histogram, stat-bin, geom-line.

Back to top