Skip to contents

Draws a hand-drawn dendrogram: leaves along one axis and each merge bracketed at its cluster height, with the right-angle elbows roughened into a hand-drawn wobble. Pass either a ready stats::hclust() object or a numeric data frame / matrix (a tree is then computed via stats::hclust(stats::dist(x))). Like geom_sketch_chord() it is a constructor returning a list of ordinary sketch layers (elbow paths + leaf labels), so it composes with +; pair it with theme_void() or theme_sketch(). Pure base stats; no new dependencies (cf. ggdendro).

Usage

geom_sketch_dendrogram(
  data,
  ...,
  orientation = c("up", "down", "left", "right"),
  method = "complete",
  distance = "euclidean",
  line_colour = "grey25",
  line_width = 0.8,
  label = TRUE,
  label_size = 3,
  label_colour = "grey20",
  roughness = 1,
  bowing = 1,
  n_passes = 2L,
  seed = NULL
)

Arguments

data

An stats::hclust() object, or a numeric data frame / matrix to cluster (non-numeric columns are dropped; row names become leaf labels).

...

Other arguments passed on to the connector layer.

orientation

Tree direction: "up" (default, root at top), "down", "left", or "right".

method, distance

Linkage method and distance metric, used only when data is not already an hclust (passed to stats::hclust() and stats::dist()). Defaults "complete" / "euclidean".

line_colour, line_width

Connector colour and width.

label

Draw leaf labels? Default TRUE.

label_size, label_colour

Label text controls.

roughness, bowing, n_passes, seed

Sketch parameters.

Value

A list of ggplot2 layers.

Examples

library(ggplot2)
ggplot() +
  geom_sketch_dendrogram(mtcars[1:8, c("mpg", "wt", "hp")], seed = 1L) +
  theme_void()