Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Tools to extract dendrogram plot data for use with ggplot
branch: master
Failed to load latest commit information.
R Hard-coded value of lab.cex - Closes #5
inst/doc
man Rebuilt documentation with roxygen2 v4.0
tests Added tests/testthat.R to run tests during R CMD check. Closes #8
vignettes Remove some vignette comments and shorten title
.Rbuildignore Integrate travis-ci build integration. Prep for #9
.gitattributes Update 23/6/2012
.travis.yml Integrate travis-ci build integration. Prep for #9
DESCRIPTION Removed Author: field since Authors@R already contains this information
NAMESPACE Rebuilt documentation with roxygen2 v4.0
NEWS Updated NEWS
README.md Added Travis build integration shield. Closes #9

README.md

ggdendro

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

Build status

Master: Build Status

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.

Example

library(ggplot2)
library(ggdendro)
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)
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")
Something went wrong with that request. Please try again.