[英]How to get a good dendrogram using R
我正在使用 R 使用 Ward 的平方欧几里德距离进行层次聚类分析。 我有一个 x 列(站)和 y 行(浮点数)的矩阵,第一行包含标题(站名)。 我想要一个很好的树状图,其中车站的名称出现在树的底部,因为我无法解释我的结果。 我的目标是找到那些相似的电台。 但是,使用以下代码,我得到了较低分支的编号 (100,101,102,...)。
Yu<-read.table("yu_s.txt",header = T, dec=",")
library(cluster)
agn1 <- agnes(Yu, metric = "euclidean", method="ward", stand = TRUE)
hcd<-as.dendrogram(agn1)
par(mfrow=c(3,1))
plot(hcd, main="Main")
plot(cut(hcd, h=25)$upper,
main="Upper tree of cut at h=25")
plot(cut(hcd, h=25)$lower[[2]],
main="Second branch of lower tree with cut at h=25")
此处提供了大量示例( http://gastonsanchez.com/blog/how-to/2012/10/03/Dendrograms.html )
两种方法:
来自基础R
hclust
hc<-hclust(dist(mtcars),method="ward")
plot(hc)
默认绘图
绘图
使用ggplot
和ggdendro
library(ggplot2)
library(ggdendro)
# basic option
ggdendrogram(hc, rotate = TRUE, size = 4, theme_dendro = FALSE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.