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")
library(collapsibleTree) 
 
# input data must be a nested data frame:
head(warpbreaks)
 
# Represent this tree:
p <- collapsibleTree( warpbreaks, c("wool", "tension", "breaks"))
p

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

Related chart types


Grouped and Stacked barplot
Treemap
Doughnut
Pie chart
Dendrogram
Circular packing



❤️ 10 best R tricks ❤️

👋 After crafting hundreds of R charts over 12 years, I've distilled my top 10 tips and tricks. Receive them via email! One insight per day for the next 10 days! 🔥