Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R How to remove labels on dendrogram?

how can I remove all that lables of this plot? Or, maybe even better, how could I make it readable?

I created it with this command:

plot(hclust(distance), main="Dissimilarity = 1 - Correlation", xlab= NA, sub=NA)

I read multiple times, that actually xlab or sub should remove the labels, but it doesn't work for me!

My plot looks like this:

enter image description here

like image 282
Essi Avatar asked Dec 13 '17 22:12

Essi


2 Answers

You can set labels=FALSE

distance = as.dist(1 - cor(mtcars))
plot(hclust(distance), main="Dissimilarity = 1 - Correlation", labels=FALSE)

Dendrogram without labels

like image 176
G5W Avatar answered Sep 22 '22 15:09

G5W


If you wish to change the size of the labels and make them readible you can use the dendextend package. See here for some really good info: Introduction to dendextend

Introduction to dendextend

The dendextend package offers a set of functions for extending dendrogram objects in R, letting you visualize and compare trees of hierarchical clusterings, you can:

  • Adjust a tree’s graphical parameters - the color, size, type, etc of its branches, nodes and labels.
  • Visually and statistically compare different dendrograms to one another.

The goal of this document is to introduce you to the basic functions that dendextend provides, and show how they may be applied. We will make extensive use of “chaining” (explained next).

Specifically:

labels_cex - set the labels’ size (using assign_values_to_leaves_nodePar)

And more specifically:

We can get a vector with the tree’s labels:

# get the labels:
dend15 %>% labels

We may also change their color and size:

par(mfrow = c(1,2))
dend15 %>% set("labels_col", "blue") %>% plot(main = "Change label's color") # change color 
dend15 %>% set("labels_cex", 2) %>% plot(main = "Change label's size") # change size

Dont forget to add the library:

# install.packages("dendextend")
library(dendextend)
like image 22
sorifiend Avatar answered Sep 19 '22 15:09

sorifiend