使用层次聚类制作简单的树状图
Make a simple dendrogram using hierarchical clustering
我有一个简单的距离矩阵:
I tried making my own distance matrix:
distances=matrix(c(0, 6.32, 11.3, 1, 10, 5.66, 4.24,
6.32, 0, 6.32, 6.08, 6, 2.83, 3.16,
11.3, 6.32, 0, 10.6, 2, 5.66, 7.07,
1, 6.08, 10.6, 0, 9.22, 5, 3.61,
10, 6, 2, 9.22, 0, 4.47, 5.83,
5.66, 2.83, 5.66, 5, 4.47, 0, 1.41,
4.24, 3.16, 7.07, 3.61, 5.83, 1.41, 0),nrow=7, ncol=7, byrow = TRUE)
But this doesn't cluster
> hc <- hclust(distances)
Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") :
missing value where TRUE/FALSE needed
我想根据测量簇之间的最小距离来创建树状图。最终产品如下所示:
有什么想法吗?帮助将不胜感激!
hclust 的输入需要 a dissimilarity structure as produced by ‘dist’
,有了矩阵,你可以把它转换成一个 'dist' 对象,然后 hclust 和 plot:
plot(hclust(as.dist(distances)))
我有一个简单的距离矩阵:
I tried making my own distance matrix:
distances=matrix(c(0, 6.32, 11.3, 1, 10, 5.66, 4.24,
6.32, 0, 6.32, 6.08, 6, 2.83, 3.16,
11.3, 6.32, 0, 10.6, 2, 5.66, 7.07,
1, 6.08, 10.6, 0, 9.22, 5, 3.61,
10, 6, 2, 9.22, 0, 4.47, 5.83,
5.66, 2.83, 5.66, 5, 4.47, 0, 1.41,
4.24, 3.16, 7.07, 3.61, 5.83, 1.41, 0),nrow=7, ncol=7, byrow = TRUE)
But this doesn't cluster
> hc <- hclust(distances)
Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") :
missing value where TRUE/FALSE needed
我想根据测量簇之间的最小距离来创建树状图。最终产品如下所示:
有什么想法吗?帮助将不胜感激!
hclust 的输入需要 a dissimilarity structure as produced by ‘dist’
,有了矩阵,你可以把它转换成一个 'dist' 对象,然后 hclust 和 plot:
plot(hclust(as.dist(distances)))