Tools to extract dendrogram plot data for use with ggplot
Latest commit 39da0aa May 20, 2016 @andrie Add downloads badge
Failed to load latest commit information.
R Do not open any plot devices during calculation of dendro_data #25 Apr 18, 2016
man Do not open any plot devices during calculation of dendro_data #25 Apr 15, 2016
tests Refactor tests. Skip test if suggested packages are not available. #16 Sep 6, 2015
vignettes Merge branch 'master' of Sep 6, 2015
.travis.yml Use new 'r' build configuration for travis Apr 14, 2016
DESCRIPTION Bump version to 0.1-20 Apr 27, 2016
NAMESPACE Rebuild documentation with roxygen2 v5.0.1 Apr 14, 2016
NEWS Update NEWS Apr 27, 2016 Add downloads badge May 20, 2016


This is a set of tools for creating dendrograms and tree plots using ggplot in R.

Project Status: Active - The project has reached a stable, usable state and is being actively developed. master: Build Status dev: Build Status CRAN_Status_Badge CRAN RStudio mirror downloads

Important functions

The ggdendro package offers a generic function to extract data and text from the various clustering models:

  • dendro_data() extracts cluster information from the model object, e.g. cluster allocation, line segment data or label data.

The dendro_data object has methods for the following classes:

  • tree
  • hclust
  • dendrogram
  • rpart

These methods create an object of class dendro, which is essentially a list of data frames. To extract the relevant data frames from the list, use the three accessor functions:

  • segment() for the line segment data
  • label() for the text for each end segment
  • leaf_label() for the leaf labels of a tree diagram

The results of these functions can then be passed to ggplot() for plotting.


hc <- hclust(dist(USArrests), "ave")
hcdata <- dendro_data(hc, type="rectangle")
ggplot() + 
  geom_segment(data=segment(hcdata), aes(x=x, y=y, xend=xend, yend=yend)) +
  geom_text(data=label(hcdata), aes(x=x, y=y, label=label, hjust=0), size=3) +
  coord_flip() + 
  scale_y_reverse(expand=c(0.2, 0))

### demonstrate plotting directly from object class hclust
ggdendrogram(hc, rotate=TRUE)

### demonstrate converting hclust to dendro using dendro_data first
hcdata <- dendro_data(hc)
ggdendrogram(hcdata, rotate=TRUE) + 
  labs(title="Dendrogram in ggplot2")