简体   繁体   English

R中的简单树状图,第一个数据列为标签

[英]Simple Dendrogram in R with first data column as labels

I created a dendrogram in R with the command below... 我使用以下命令在R中创建了树状图...

I have been trying to find the command to replace the number with the name of the County which is the first column in the data set or load the plot with the name of the county instead of the number. 我一直在尝试找到用数字替换县名的命令,县名是数据集的第一列,或者用县名而不是数字来加载绘图。 If anyone could help that would be appreciated. 如果有人可以帮助,将不胜感激。

hc = hclust(dist(NYCounty))
plot(hc)

当前情节

NYCounty的数据

You can pass it to labels argument in plot.hclust . 您可以将其传递给plot.hclust labels参数。 A reproducible example showing this: 可重现的示例显示如下:

# example from ?hclust
hc <- hclust(dist(USArrests), "ave")
plot(hc)
# custom labels
df <- data.frame(foo=paste("hi", 1:50))
plot(hc, labels=df$foo)

Is this what you want? 这是你想要的吗?

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

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