A small physical solver behind geom_sketch_text_repel() /
geom_sketch_label_repel(). Each label starts near its anchor and is pushed
by three forces, iterated to rest: boxes that overlap shove each other apart
along their axis of least penetration (preferring an axis with room left
inside the bounds, so pairs pressed into a panel corner escape along the
edge instead of staying stuck); a box covering any anchor point slides
off it; and a weak spring pulls each box back toward its own anchor so labels
stay close to what they name. Positions are clamped to xlim / ylim.
repel_layout(
ax,
ay,
w,
h,
xlim = c(-Inf, Inf),
ylim = c(-Inf, Inf),
box_padding = 0.1,
point_padding = 0.05,
max_iter = 2000L,
seed = NULL
)A list with x, y (the resolved box centres) and iter (iterations
actually run).
Anchor points (one per label), in a single isotropic space (e.g. device inches).
Label box width and height (same units), recycled to the anchors.
Length-2 bounds the box centres are kept within.
Extra clearance around boxes and around anchor points, in the same units.
Maximum solver iterations. Default 2000.
Integer seed (for the tiny start jitter that separates labels sharing an anchor).
Other sketch-core:
arrowhead(),
curve_fill(),
engrave_fill(),
engrave_ladder(),
hachure_fill(),
hachure_fill_multi(),
leader_path(),
rough_arc(),
rough_bezier(),
rough_ellipse(),
roughen_polyline(),
sketch_arrowheads(),
sketch_fill(),
sketch_fill_multi(),
spray_scatter(),
stroke_profile(),
stroke_ribbon(),
treemap_layout(),
wash_bleed(),
watercolor_wash(),
watercolor_wash_multi()
repel_layout(c(0, 0.1, 0.1), c(0, 0, 0.05), w = 0.4, h = 0.2, seed = 1L)
Run the code above in your browser using DataLab