Dendrogram





A dendrogram (or tree diagram) is a network structure. It is constituted of a root node that gives birth to several nodes connected by edges or branches. The last nodes of the hierarchy are called leaves. Many options are available to build one with R. This sections aims to lead you toward the best strategy for your data.

Two types of dendrogram


Dendrograms can be built from:





Dendrogram from hierarchical data.

The ggraph package is the best option to build a dendrogram from hierarchical data with R. It is based on the grammar of graphic and thus follows the same logic that ggplot2.

The collapsibletree package is an htmlwidget: it automatically builds collapsible interactive tree diagram. On the chart below, click a node to reveal the next branch, and zoom in/out if necessary.

How to export to .png Chart code

Dendrogram from clustering result.

Hierarchical clustering is a common task in data science and can be performed with the hclust() function in R. The following examples will guide you through your process, showing how to prepare the data, how to run the clustering and how to build an appropriate chart to visualize its result.





More customization with dendextend.

The dendextend package allows to go one step further in term of dendrogram customization. Here is a set of examples showing the main possibilities, like adding color bar on the bottom, drawing 2 trees face to face and more.

Related chart types


Grouped and Stacked barplot
Treemap
Doughnut
Pie chart
Dendrogram
Circular packing