Labels in Dendrogram

 

To add the labels into the dendrogram we will use geom_node_text() which will add the labels into the graph into a hierarchical structure

 

R




# libraries
library(ggraph)
library(igraph)
library(tidyverse)
  
# create a data frame
data <- data.frame(
  level1="CEO",
  level2=c( rep("boss1",4), rep("boss2",4)),
  level3=paste0("mister_", letters[1:8])
)
  
# transform it to a edge list!
edges_level1_2 <- data %>% select(
  level1, level2) %>% unique %>% rename(
  from=level1, to=level2)
 
edges_level2_3 <- data %>% select(
  level2, level3) %>% unique %>% rename(
  from=level2, to=level3)
edge_list=rbind(edges_level1_2, edges_level2_3)
  
# Now we can plot that
graph_Data <- graph_from_data_frame( edge_list )
ggraph(graph_Data, layout = 'dendrogram') +
  geom_edge_diagonal() +
  geom_node_text(aes( label=name)) +
  theme_void()


 

 

Output:

 

Plot Dendrogram with R and ggraph

In this article, we are going to see how to customize dendrogram. It is also known as a tree diagram and it is a visual representation of the hierarchical relationship between items. A dendrogram’s main purpose is to figure out the best approach to assign objects to clusters. 

Similar Reads

Creating Basic Dendrogram

To create a dendrogram we will igraph package which is used for creating and manipulating graphs and analyzing networks graph. So for creating a dendrogram, we will create a dataframe into the hierarchical data structure and then transform it into an edge list. To plot a Dendrogram we will use the following syntax:...

Circular Layout Dendrogram

...

Edge style Dendrogram

...

Labels in Dendrogram

...

Customize Labels in Dendrogram

...

Customize Nodes in Dendrogram

...