简体   繁体   English

R如何去除树状图上的标签?

[英]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! 我读了很多遍,实际上xlabsub应该删除标签,但这对我不起作用!

My plot looks like this: 我的情节看起来像这样:

在此处输入图片说明

If you wish to change the size of the labels and make them readible you can use the dendextend package. 如果希望更改标签的大小并使它们可读,则可以使用dendextend软件包。 See here for some really good info: Introduction to dendextend 请参阅此处以获取一些非常好的信息: dendextend简介

Introduction to dendextend 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: dendextend软件包提供了一组用于在R中扩展树状图对象的功能,使您可以可视化和比较分层聚类的树,您可以:

  • 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. 本文档的目的是向您介绍dendextend提供的基本功能,并展示如何应用它们。 We will make extensive use of “chaining” (explained next). 我们将广泛使用“链接”(下面说明)。

Specifically: 特别:

labels_cex - set the labels' size (using assign_values_to_leaves_nodePar) labels_cex-设置标签的大小(使用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) 

You can set labels=FALSE 您可以设置labels=FALSE

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

没有标签的树状图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM