Introduction to tree diagram with R and ggraph



This posts is a step by step introduction to building dendrograms with R and the ggraph package. It provides several examples based on different input formats with explanation and reproducible code.

Dendrogram section Data to Viz

This page aims to describe how to make a basic dendrogram representing hierarchical data with the ggraph library. Two input formats are considered:

Please visit this page to learn how to custom these dendrograms. If you want to create a dendrogram from clustering result, visit the dendrogram section of the gallery.

Dendrogram from edge list


Edge list is the most convenient format to use ggraph. Follow those steps:

edge list input data example

Edge list data format

Dendrogram from a nested dataframe


Another common format is the nested data frame. The code below shows how to easily transform it into a nested data frame. Once it is done, just apply the code described above once more.

Nested dataframe input data example

Nested dataframe format

Related chart types


Grouped and Stacked barplot
Treemap
Doughnut
Pie chart
Dendrogram
Circular packing



Contact

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 yan.holtz.data with gmail.com.

Github Twitter