Interactive dendrogram with R

This post describes how to use the CollapsibleTree package to build an interactive tree diagram. Explanation and reproducible code provided

Dendrogram section Data to Viz

The collapsibletree package is the best option to build interactive dendrogram with R.

On the chart above, you can click a node to reveal the following branch that is currently collapsed.

The input must be a data frame that stores the hierarchical information. Basically, each row describes a complete path from the root to the leaf. In this example, the warpbreaks dataset has 3 columns: wool, tension and breaks.

# Load library
# install.packages("collapsibleTree")
# input data must be a nested data frame:
# Represent this tree:
p <- collapsibleTree( warpbreaks, c("wool", "tension", "breaks"))

# save the widget
# library(htmlwidgets)
# saveWidget(p, file=paste0( getwd(), "/HtmlWidget/dendrogram_interactive.html"))

Related chart types

Grouped and Stacked barplot
Pie chart
Circular packing


This document is a work by Yan Holtz. Any feedback is highly encouraged. You can fill an issue on Github, drop me a message on Twitter, or send an email pasting with

Github Twitter