position-nudge

Shift every row’s x and y by a fixed amount in data units.

Usage

position-nudge(
  x: 0,
  y: 0,
)

Parameters

Parameter Default Description
x 0 Offset added to the x value of each row.
y 0 Offset added to the y value of each row.

Returns

Position dictionary with name: "nudge", consumed by plot.

Examples

Offset text labels above their points using a default position-nudge().

#let d = (
  (x: 1, y: 2, lab: "alpha"),
  (x: 2, y: 4, lab: "beta"),
  (x: 3, y: 3, lab: "gamma"),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", label: "lab"),
  layers: (
    geom-point(size: 3pt),
    geom-text(position: "nudge"),
  ),
  width: 10cm,
  height: 6cm,
)

Scatter chart with x on the x-axis and y on the y-axis; three points each accompanied by a text label sitting just off the point so the labels do not overlap the marker.

Scatter chart with x on the x-axis and y on the y-axis; three points each accompanied by a text label sitting just off the point so the labels do not overlap the marker.

Pass explicit x and y offsets to flow labels diagonally off the points.

#let d = (
  (x: 1, y: 2, lab: "alpha"),
  (x: 2, y: 4, lab: "beta"),
  (x: 3, y: 3, lab: "gamma"),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", label: "lab"),
  layers: (
    geom-point(size: 3pt),
    geom-text(position: position-nudge(x: 0.2, y: 0.3)),
  ),
  width: 10cm,
  height: 6cm,
)

Scatter chart with x on the x-axis and y on the y-axis; three points each paired with a text label shifted diagonally up and to the right by fixed offsets.

Scatter chart with x on the x-axis and y on the y-axis; three points each paired with a text label shifted diagonally up and to the right by fixed offsets.

See also

position-jitter, geom-text.

Back to top