Skip to contents

The hand-drawn answer to ggrepel: text (geom_sketch_text_repel()) or boxed labels (geom_sketch_label_repel()) that are nudged apart so they do not overlap one another or cover the data points, each joined back to its anchor by a roughened leader line when it has moved. Placement is solved at draw time by repel_layout() in device space, so it is even on any panel aspect.

Usage

GeomSketchTextRepel

GeomSketchLabelRepel

geom_sketch_text_repel(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  ...,
  roughness = 1,
  bowing = 0.6,
  n_passes = 2L,
  seed = NULL,
  padding = 0.07,
  corner_radius = 0.3,
  box_padding = 0.1,
  point_padding = 0.05,
  min_segment = 0.06,
  max_iter = 2000L,
  family = NULL,
  na.rm = FALSE,
  show.legend = FALSE,
  inherit.aes = TRUE
)

geom_sketch_label_repel(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  ...,
  roughness = 1,
  bowing = 0.6,
  n_passes = 2L,
  seed = NULL,
  padding = 0.09,
  corner_radius = 0.3,
  box_padding = 0.12,
  point_padding = 0.05,
  min_segment = 0.06,
  max_iter = 2000L,
  family = NULL,
  na.rm = FALSE,
  show.legend = FALSE,
  inherit.aes = TRUE
)

Arguments

mapping, data, stat, position, show.legend, inherit.aes

Standard layer arguments. Requires x, y and label aesthetics.

...

Other arguments passed on to the layer.

roughness, bowing, n_passes, seed

Sketch parameters for the leader / box.

padding

Text clearance inside the box (and around bare text), inches.

corner_radius

Box corner rounding (label variant). Fraction of half-side; default 0.3.

box_padding, point_padding

Extra clearance kept between boxes and around the anchor points, in inches.

min_segment

Shortest leader drawn, in inches; below this no leader is shown (the label is close enough to its anchor).

max_iter

Repel solver iteration cap. Default 2000.

family

Font family for the text. Defaults to the theme's text family.

na.rm

Drop missing values silently? Default FALSE.

Value

A ggplot2 layer object.

Details

Unlike most ggsketch geoms the glyphs are not roughened (the sketch of text is a handwriting font, ADR-0007); the leader and the label box are. Like geom_sketch_text(), family defaults to the theme's text family.

Examples

library(ggplot2)
df <- head(mtcars, 12)
df$name <- rownames(df)
ggplot(df, aes(wt, mpg, label = name)) +
  geom_sketch_point(seed = 1L) +
  geom_sketch_text_repel(family = "", seed = 1L) +
  theme_sketch()