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:

The dendro_data object has methods for the following classes:

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:

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")

andrie/ggdendro documentation built on June 3, 2017, 7:02 p.m.