Learn R Programming

ggsketch (version 2.0.0)

geom_sketch_text: Sketchy text and labels

Description

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 )

Value

A ggplot2 layer object.

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.

See Also

Other sketch-geoms: GeomSketchAbline, GeomSketchArrow, GeomSketchBoxplot, GeomSketchBracket, GeomSketchCallout, GeomSketchChicklet, GeomSketchCol, GeomSketchContourFilled, GeomSketchCurve, GeomSketchDotplot, GeomSketchDumbbell, GeomSketchEdge, GeomSketchEllipse, GeomSketchEngrave, GeomSketchGantt, GeomSketchHex, GeomSketchLine, GeomSketchLinerange, GeomSketchLollipop, GeomSketchMarkCircle, GeomSketchMarkHull, GeomSketchPath, GeomSketchPoint, GeomSketchPolygon, GeomSketchRect, GeomSketchRibbon, GeomSketchRug, GeomSketchSegment, GeomSketchSfPolygon, GeomSketchSlope, GeomSketchSmooth, GeomSketchSpoke, GeomSketchTextRepel, GeomSketchViolin, StatSketchBeeswarm, StatSketchCalendar, StatSketchDensityRidges, StatSketchFunnel, StatSketchPie, StatSketchPyramid, StatSketchRadar, StatSketchStream, StatSketchTreemap, StatSketchWaffle, StatSketchWaterfall, annotate_sketch(), annotate_sketch_arrow(), annotate_sketch_callout(), annotate_sketch_highlight(), geom_sketch_alluvial(), geom_sketch_arc_diagram(), geom_sketch_bin2d(), geom_sketch_bump(), geom_sketch_chord(), geom_sketch_contour(), geom_sketch_count(), geom_sketch_dendrogram(), geom_sketch_density(), geom_sketch_density2d(), geom_sketch_ecdf(), geom_sketch_function(), geom_sketch_histogram(), geom_sketch_jitter(), geom_sketch_marimekko(), geom_sketch_mosaic(), geom_sketch_parallel(), geom_sketch_qq(), geom_sketch_quantile(), geom_sketch_rose(), geom_sketch_sunburst(), sketch_graph()

Examples

Run this code
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 instead (see
# `ggsketch_check_fonts()`). That requires a font-capable device (ragg,
# svglite, cairo); pass `family = ""` (above) for fully portable output on any
# device, including the base pdf() / postscript().

Run the code above in your browser using DataLab