Learn R Programming

tinyplot (version 0.8.0)

repel_text: Force-directed text repelling

Description

Resolves overlapping text labels using a two-phase algorithm: (1) push overlapping labels apart symmetrically, (2) spring-pull labels back toward their anchors without reintroducing overlaps.

Usage

repel_text(
  x,
  y,
  widths,
  heights,
  anchor_x = x,
  anchor_y = y,
  min_gap = 0,
  iterations = 20,
  axis = "both"
)

Value

A list with elements x and y giving adjusted positions.

Arguments

x, y

Numeric vectors of current label positions.

widths, heights

Numeric vectors of label bounding box dimensions (in the same units as x and y).

anchor_x, anchor_y

Numeric vectors of original target positions that labels are pulled back toward during the spring pass. Defaults to x and y.

min_gap

Minimum padding between labels. Default 0.

iterations

Maximum number of repulsion iterations. Default 20.

axis

Movement constraint: "both" (default), "x", or "y".