Dendrogram

Hierarchies
A hierarchical clustering drawn straight from hclust(), cut into coloured groups.

vdendrogram() draws a base hclust (or dendrogram) as a node-link tree: leaves along one edge, each merge at its height, joined by right-angle brackets. It coerces the clustering to vgraph()’s node and edge tables, so the result is an ordinary plot spec you can theme and render like any other.

Pass k to cut the tree with cutree() and colour the branches and leaf labels by cluster. Branches above the cut, where the clusters join, stay grey.

hc <- hclust(dist(scale(mtcars)), method = "ward.D2")
p <- vdendrogram(hc, k = 4)

With 32 leaves the labels are tight along the bottom. direction = "right" grows the tree sideways and lays the labels out horizontally, which reads better for a long list of leaves.

p <- vdendrogram(hc, k = 4, direction = "right")

For finer control, skip the preset. vgraph() takes the clustering directly, and layout = "dendrogram" reads the merge heights; you then add the marks yourself. layout = "unrooted" (from graphlayouts) instead spreads the tree across the plane the way phylogenies are drawn.

Back to top