简体   繁体   English

R中树状图中的标签

[英]Labels in dendrogram in R

I am working on dendrogram 我正在研究树状图

plot(clust.res, hang=-1, main=dedro,labels=data1$Name.of.the.variety)

Then message that I get are: 然后我得到的消息是:

Warning messages:
"labels" is not a graphical parameter

That makes sense. 那讲得通。 In general, the plot.dendrogram function does not have a labels parameter, and does not allow you to modify the labels of the dendrogram it plots. 通常, plot.dendrogram函数没有labels参数,并且不允许您修改其绘制的树状图的标签。

It is, however, possible to do using the dendextend R package . 但是,可以使用dendextend R包

Here is a simple example for you to go through: 这是一个简单的示例,供您查看:

# some data and create the dendrogram
DATA <- 1:4
hc <- hclust(dist(DATA))
dend <- as.dendrogram(hc)

# Get dendextend for editing the labels
if(!require(dendextend)) install.packages("dendextend") 
library(dendextend)
# Copy the object, and edit its labels
dend2 <- dend
labels(dend2) <- c("one", "two", "3", "four")

# compare the two dendrograms:
par(mfrow = c(1,2))
plot(dend, main = "original dend")
plot(dend2, main = "dend with edited labels")

The dendextend package also allows you to modify the labels color and size, see here for examples . dendextend包还允许您修改标签的颜色和大小, 请参见此处的示例

在此处输入图片说明

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

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