geom-text

Text label layer reading strings from the label aesthetic.

One text block is drawn per row at the mapped (x, y) with an optional offset via dx and dy.

Usage

geom-text(
  mapping: none,
  data: none,
  size: 8pt,
  colour: auto,
  alpha: auto,
  anchor: "center",
  dx: 0,
  dy: 0,
  stat: "identity",
  position: "identity",
  inherit-aes: true,
)

Parameters

Parameter Default Description
mapping none Layer-specific aesthetic mapping built with aes. Must map x, y, and label.
data none Layer-specific dataset. Falls back to the plot data when none.
size 8pt Text size (a Typst length).
colour auto Fixed text colour. auto inherits the theme ink. Used when no colour mapping is active.
alpha auto Text opacity in [0, 1]. auto honours any mapped alpha aesthetic.
anchor "center" CeTZ anchor (e.g., "center", "west") controlling placement.
dx 0 Horizontal offset, as a number (canvas units, 1 = 1cm) or a Typst length (e.g., 4pt, 2mm).
dy 0 Vertical offset, as a number (canvas units, 1 = 1cm) or a Typst length (e.g., 4pt, 2mm).
stat "identity" Statistical transform name. Usually "identity".
position "identity" Position adjustment name. Usually "identity"; pass "nudge" to shift labels off their points.
inherit-aes true Whether to merge the plot-level mapping into this layer’s mapping.

Returns

Layer dictionary consumed by plot.

Examples

Labels nudged above their points via dy.

#let d = (
  (x: 1, y: 2, name: "a"),
  (x: 2, y: 4, name: "b"),
  (x: 3, y: 3, name: "c"),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", label: "name"),
  layers: (
    geom-point(size: 2pt),
    geom-text(dy: 0.2),
  ),
  width: 10cm,
  height: 6cm,
)

Three point markers at (x, y) with plain text labels (a, b, c) nudged above each point via a vertical offset.

Three point markers at (x, y) with plain text labels (a, b, c) nudged above each point via a vertical offset.

Map colour and use anchor: "west" to flow labels to the right of each point.

#let d = (
  (x: 1, y: 2, name: "a", grp: "x"),
  (x: 2, y: 4, name: "b", grp: "y"),
  (x: 3, y: 3, name: "c", grp: "x"),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", label: "name", colour: "grp", fill: "grp"),
  layers: (
    geom-point(size: 2pt),
    geom-text(anchor: "west", dx: 0.15),
  ),
  width: 10cm,
  height: 6cm,
)

Three point markers at (x, y) with text labels (a, b, c) flowing right of each point and coloured by group x or y.

Three point markers at (x, y) with text labels (a, b, c) flowing right of each point and coloured by group x or y.

See also

geom-label, aes.

Back to top