Skip to contents

Draws a hand-drawn dumbbell: a roughened connector from x to xend on a shared y, capped with a sketch point at each end. Ideal for showing the change or gap between two paired values per category (cf. ggalt::geom_dumbbell()).

Usage

GeomSketchDumbbell

geom_sketch_dumbbell(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  ...,
  colour_x = NULL,
  colour_xend = NULL,
  roughness = 0.6,
  point_roughness = 0.4,
  bowing = 0.4,
  n_passes = 2L,
  seed = NULL,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping

Aesthetic mappings created by ggplot2::aes(). Requires x, xend and y.

data

Data to display.

stat

Statistical transformation. Default "identity".

position

Position adjustment. Default "identity".

...

Other arguments passed on to the layer.

colour_x

Colour of the dot at x. Default NULL (uses colour).

colour_xend

Colour of the dot at xend. Default NULL (uses colour).

roughness

Connector roughness (0 = straight). Default 0.6.

point_roughness

Roughness of the end dots. Default 0.4.

bowing

Non-negative bowing multiplier. Default 0.4.

n_passes

Number of stroke passes. Default 2.

seed

Integer seed. NULL uses getOption("ggsketch.seed", 1L).

na.rm

Remove missing values silently? Default FALSE.

show.legend

Logical; include in legend?

inherit.aes

Override default aesthetics?

Value

A ggplot2 layer object.

Examples

library(ggplot2)
df <- data.frame(g = c("Alpha", "Bravo", "Charlie", "Delta"),
                 before = c(20, 35, 28, 42),
                 after  = c(34, 51, 22, 47))
ggplot(df, aes(x = before, xend = after, y = g)) +
  geom_sketch_dumbbell(colour_x = "#B03A2E", colour_xend = "#1F618D",
                       seed = 1L) +
  theme_sketch()