geom-polygon

Polygon layer: one closed filled polygon per group.

Rows are connected in input order and the polygon is closed back to the first vertex. Use group, colour, fill, or linetype to split rows into separate polygons.

Usage

geom-polygon(
  mapping: none,
  data: none,
  colour: auto,
  fill: auto,
  stroke: none,
  alpha: auto,
  stat: "identity",
  position: "identity",
  inherit-aes: true,
)

Parameters

Parameter Default Description
mapping none Layer-specific aesthetic mapping built with aes. Must map x, y.
data none Layer-specific dataset. Falls back to the plot data when none.
colour auto Fixed outline colour. auto resolves via the colour scale, falling back to the theme ink only when neither colour nor fill is set.
fill auto Fixed fill colour. auto resolves via the fill scale.
stroke none Outline thickness (a Typst length) or stroke dictionary; none disables the outline.
alpha auto Fill opacity in [0, 1].
stat "identity" Statistical transform name. Usually "identity".
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

Two filled triangles, each defined by three vertex rows in a shared column.

#let d = (
  (x: 0, y: 0, k: "a"),
  (x: 2, y: 0, k: "a"),
  (x: 1, y: 2, k: "a"),
  (x: 3, y: 1, k: "b"),
  (x: 5, y: 1, k: "b"),
  (x: 4, y: 3, k: "b"),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", fill: "k"),
  layers: (geom-polygon(alpha: 0.5),),
  width: 10cm,
  height: 6cm,
)

Two translucent filled triangles defined by three (x, y) vertex rows each with groups a and b coloured by fill aesthetic.

Two translucent filled triangles defined by three (x, y) vertex rows each with groups a and b coloured by fill aesthetic.

A regular pentagon constructed from sampled angles.

#let n = 5
#let d = range(0, n).map(i => (
  x: calc.cos(2 * calc.pi * i / n),
  y: calc.sin(2 * calc.pi * i / n),
))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-polygon(
    fill: rgb("#4c78a8"),
    stroke: 1pt + black,
    alpha: 0.7,
  ),),
  width: 10cm,
  height: 6cm,
)

Regular blue pentagon centred at the origin with five vertices sampled around the unit circle and black outline.

Regular blue pentagon centred at the origin with five vertices sampled around the unit circle and black outline.

See also

geom-rect, geom-area.

Back to top