Skip to contents

A hand-drawn take on network/graph plotting. geom_sketch_edge() draws a roughened connector between (x, y) and (xend, yend); geom_sketch_node() draws roughened node markers with optional handwriting labels. Pair them with sketch_graph(), which computes node positions with a pure-R force-directed layout (force_layout()) and returns the two data frames these geoms expect - no graph package required.

Usage

GeomSketchEdge

geom_sketch_edge(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  ...,
  curvature = 0,
  roughness = 1,
  bowing = 1,
  n_passes = 2L,
  seed = NULL,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

GeomSketchNode

geom_sketch_node(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  ...,
  roughness = NULL,
  bowing = NULL,
  n_passes = 2L,
  seed = NULL,
  label_size = 3.2,
  label_colour = "grey15",
  label_family = NULL,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping

Aesthetic mappings created by ggplot2::aes().

data

Data to display. For geom_sketch_edge() the rows need x/y/xend/yend; for geom_sketch_node() they need x/y (and an optional label). Typically the $edges and $nodes from sketch_graph().

stat, position

Statistical transformation and position adjustment. Default "identity" for both.

...

Other arguments passed on to the layer.

curvature

Edge bend. 0 (default) draws straight roughened edges; non-zero gives arc edges (a quadratic Bezier), like geom_sketch_curve().

roughness, bowing, n_passes, seed

Sketch parameters; see geom_sketch_path(). For geom_sketch_node(), roughness is a mappable aesthetic (per node).

na.rm

Remove missing values silently? Default FALSE.

show.legend, inherit.aes

Standard layer arguments.

label_size

Handwriting label size (mm). Default 3.2.

label_colour

Label colour. Default "grey15".

label_family

Label font family. Defaults to the first installed handwriting face (as geom_sketch_text() uses).

Value

A ggplot2 layer object.

Examples

library(ggplot2)
edges <- data.frame(
  from = c("A", "A", "B", "C", "C", "D"),
  to   = c("B", "C", "C", "D", "E", "E")
)
g <- sketch_graph(edges, seed = 1L)
ggplot() +
  geom_sketch_edge(data = g$edges,
                   aes(x = x, y = y, xend = xend, yend = yend), seed = 1L) +
  geom_sketch_node(data = g$nodes,
                   aes(x = x, y = y, label = name), size = 6, seed = 2L) +
  coord_equal() +
  theme_void()