8

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

Tom Aranda
  • 5,919
  • 11
  • 35
  • 51
Essi
  • 761
  • 3
  • 12
  • 22

2 Answers2

7

You can set labels=FALSE

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

Dendrogram without labels

G5W
  • 36,531
  • 10
  • 47
  • 80
  • 6
    This method does not seem to work when the dendogram have been adjusted with dendextend. In that case it seems like the best is to just use dendextend to change the font to white or background color since there is no way to set font to 0, at least to mey knowledge. – Ahdee Sep 10 '19 at 23:46
6

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)
sorifiend
  • 5,927
  • 1
  • 28
  • 45