Skip to contents

geom_sketch_text() and geom_sketch_label() add text in a handwriting font, the sketch counterparts of ggplot2::geom_text() and ggplot2::geom_label(). Unlike the other geoms the strokes are not geometrically roughened — the hand-drawn feel comes from the font (see ggsketch_check_fonts() for which faces are available). If no handwriting font is installed they render with the device default family.

Usage

geom_sketch_text(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  ...,
  family = NULL,
  nudge_x = 0,
  nudge_y = 0,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

geom_sketch_label(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  ...,
  family = NULL,
  nudge_x = 0,
  nudge_y = 0,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping

Set of aesthetic mappings created by ggplot2::aes(). Requires a label aesthetic.

data

Data to display.

stat

Statistical transformation (default "identity").

position

Position adjustment (default "identity").

...

Other arguments passed on to ggplot2::layer(), such as size, colour, angle, or hjust.

family

Font family. By default the first installed handwriting face is used; pass an explicit family to override, or "" for the device default.

nudge_x, nudge_y

Horizontal and vertical adjustment to nudge labels by. Useful for offsetting text from points. Cannot be used together with an explicit position.

na.rm

If FALSE (default), missing values are removed with a warning.

show.legend

Logical. Should this layer be included in the legend?

inherit.aes

If FALSE, override the default aesthetics.

Value

A ggplot2 layer object.

Examples

library(ggplot2)
df <- data.frame(x = c(1, 2, 3), y = c(2, 3, 1),
                 lab = c("alpha", "bravo", "charlie"))

# `family = ""` uses the device default, so this runs on any device.
ggplot(df, aes(x, y, label = lab)) +
  geom_sketch_text(size = 6, family = "") +
  theme_sketch()


# With no `family`, the first installed handwriting font is used. Render with
# a font-capable device (ragg, svglite, cairo) to see it — the base pdf() /
# postscript() devices cannot use unregistered system fonts.
if (FALSE) { # \dontrun{
ggplot(df, aes(x, y, label = lab)) +
  geom_sketch_text(size = 6) +
  theme_sketch()
} # }