Skip to content
naulon

No retraction, correction or concern found when last checked on Oct 15, 2026.

dendextend: an R package for visualizing, adjusting and comparing trees of hierarchical clustering

Tal Galili

Bioinformatics · 2015 · CC BY

doi:10.1093/bioinformatics/btv428

Abstract

Summary: dendextend is an R package for creating and comparing visually appealing tree diagrams. dendextend provides utility functions for manipulating dendrogram objects (their color, shape and content) as well as several advanced methods for comparing trees to one another (both statistically and visually). As such, dendextend offers a flexible framework for enhancing R's rich ecosystem of packages for performing hierarchical clustering of items. Availability and implementation: The dendextend R package (including detailed introductory vignettes) is available under the GPL-2 Open Source license and is freely available to download from CRAN at: (http://cran.r-project.org/package=dendextend) Contact: Tal.Galili@math.tau.ac.il

Full text

From PubMed Central, U.S. National Library of Medicine, as current on Oct 16, 2026. Paragraph numbers are ours, so an answer can point at one.

1 Introduction

Hierarchical cluster analysis (HCA) is a widely used family of unsupervised statistical methods for classifying a set of items into some hierarchy of clusters (groups) according to the similarities among the items. The R language—a leading, cross-platform and open source statistical programming environment—has many implementations of HCA algorithms. The output of these various algorithms is stored in the hclust object class, while the dendrogram class is an alternative object class that is often used as the go-to intermediate representation step for visualizing an HCA output.

In many R packages, a figure output is adjusted by supplying the plot function with both an object to be plotted and various graphical parameters to be modified (colors, sizes, etc.). However, different behavior happens in the (base R) plot.dendrogram function, in which the function is given a dendrogram object that contains within itself (most of) the graphical parameters to be used when plotting the tree. Internally, the dendrogram class is represented as a nested list of lists with attributes for colors, height, etc. (with useful methods from the stats package). Until now, no comprehensive framework has been available in R for flexibly controlling the various attributes in dendrogram's class objects.

The dendextend package aims to fill this gap by providing a significant number of new functions for controlling a dendrogram's structure and graphical attributes. It also implements methods for visually and statistically comparing different dendrogram objects. The package is extensively validated through unit-testing, offers a C++ speed-up for some of the core functions through the dendextendRcpp package, and includes three detailed vignettes.

The dendextend package is primarily geared towards HCA. For phylogeny analysis, the phylo object class (from the ape package) is recommended. A comprehensive comparison of dendextend, ape, as well as other software for tree analysis, is available in the supplementary materials.

2.1 Updating a dendrogram for visualization

The function set(dend, what, value), in dendextend, accepts a dendrogram (i.e. dend) as input and returns it after some adjustment. The parameter what is a character indicating the property of the tree to be adjusted (see Table 1) based on value. The user can repeatedly funnel a tree, through different configuration of the set function, until a desired outcome is reached.

Figure 1 is created by clustering a vector of 1 to 5 into a dendrogram:

The above code uses the convenient forward-pipe operator %>%, which is just like running:

Next, the tree is plotted after repeatedly using the set function:

The ‘value’ vector is recycled in a depth-first fashion, with the root node considered as having a branch (which is not plotted by default). The parameters of the new tree can be explored using the functions get_nodes_attr and get_leaves_attr. Also, we can rotate and prune a tree with the respective functions.

2.2 Comparing two dendrograms

The tanglegram function allows the visual comparison of two dendrograms, from different algorithms or experiments, by facing them one in front of the other and connecting their labels with lines. Distinct branches are marked with a dashed line. For easier and nicer plotting, dendlist concatenates the two dendrograms together, while untangle attempts to rotate trees with un-aligned labels in search for a good layout. Figure 2 demonstrates a comparison of two clustering algorithms (single versus complete linkage) on a subset of 15 flowers from the famous Iris dataset. The entanglement function measures the quality of the tanglegram layout. Measuring the correlation between tree topologies can be calculated using different measures with cor.dendlist, Bk_plot, or dist.dendlist. Permutation test and bootstrap confidence intervals are available. The above methods offer sensitivity and replicability analysis for researchers who are interested in validating their hierarchical clustering results.

3 Enhancing other packages

The R ecosystem is abundant with functions that use dendrograms, and dendextend offers many functions for interacting and enhancing their visual display: The function rotate_DendSer rotates a dendrogram to optimize a visualization-based cost function. Other functions allow the highlighting of un-even creation of clusters with the dynamicTreeCut package, as well as of ‘significant’ clusters based on the pvclust package. Previously mentioned functions can be combined to create a highly customized (rotated, colorful, etc.) static heatmap using heatplot.2 from gplots, or a D3 interactive heatmap using the d3heatmap package. The circlize_dendrogram function produces a simple circular tree layout, while more complex circular layouts can be achieved using the circlize package. Aside from R base graphics, a ggplot2 dendrogram may be created using the as.ggdend function.

In conclusion, the dendextend package simplifies the creation, comparison and integration of dendrograms into fine-tuned (publication quality) graphs. A demonstration of the package on various datasets is available in the supplementary materials.

References 16

  1. 1.

    Chipman H. Tibshirani R. (2006 ) Hybrid hierarchical clustering with applications to microarray data. Biostatistics, 7, 286–301.

    Not in our library10.1093/biostatistics/kxj007

  2. 2.

    Eddelbuettel D. François R. (2011 ) Rcpp: Seamless R and C++ Integration. J. Stat. Softw., 40, 1–18.

    Not in our library

  3. 3.

    Fowlkes E.B. Mallows C.L. (1983 ) A method for comparing two hierarchical clusterings. J. Am. Stat. Assoc., 78, 553–569.

    Not in our library

  4. 4.

    Gu Z. (2014 ) circlize implements and enhances circular visualization in R. Bioinformatics, 30, 1–2.

    Not in our library10.1093/bioinformatics/btu393

  5. 5.

    Hurley C.B. Earle D. (2013 ) DendSer: Dendrogram seriation: ordering for visualisation, R, package version 1.0.1.

    Not in our library

  6. 6.

    Langfelder P. (2008 ) Defining clusters from a hierarchical cluster tree: the Dynamic Tree Cut package for R. Bioinformatics, 24, 719–720.

    Not in our library10.1093/bioinformatics/btm563

  7. 7.

    Maechler M. (2015 ) cluster: Cluster Analysis Basics and Extensions. R package version 2.0.3.

    Not in our library

  8. 8.

    Milton B.S. Wickham H. (2014 ) magrittr: magrittr—a forward-pipe operator for R, R package version 1.5.

    Not in our library

  9. 9.

    Paradis E. (2004 ) APE: Analyses of Phylogenetics and Evolution in R language. Bioinformatics, 20, 289–290.

    Not in our library10.1093/bioinformatics/btg412

  10. 10.

    R Core Team. (2014 ) R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria URL http://www.R-project.org/.

    Not in our library

  11. 11.

    Schmidtlein S. (2010 ) A brute-force approach to vegetation classification. J. Veg. Sci., 21, 1162–1171.

    Not in our library

  12. 12.

    Sokal R.R. Rohlf F.J. (1962 ) The comparison of dendrograms by objective methods. Taxon, 11, 33–40.

    Not in our library

  13. 13.

    Suzuki R. Shimodaira H. (2006 ) Pvclust: an R package for assessing the uncertainty in hierarchical clustering. Bioinformatics, 22, 1540–1542.

    Not in our library10.1093/bioinformatics/btl117

  14. 14.

    Warnes G.R. (2014 ) gplots: Various R programming tools for plotting data, R package version 2.6.0.

    Not in our library

  15. 15.

    Wickham H. (2011 ) testthat: Get started with testing. R. J., 3, 5–10.

    Not in our library

  16. 16.

    Witten D.M. Tibshirani R. (2010 ) A framework for feature selection in clustering. J. Am. Stat. Assoc., 105, 713–726.

    Not in our library10.1198/jasa.2010.tm09415

Cited by papers we hold 28

and 8 more

Reads

Read by people on this page

None yet.

Checked or read by AI through naulon

None yet.

A person counts once a day per paper. We keep no cookie and no address: a reader is a hash that changes every day. Any month under five reads shows no number.

Are you an author?

Is this your paper?

Claim it to add your note and be paid when agents cite it. Free.