[英]How to get the point coordinates and cluster labels from R clusplot()
我使用k-medoids算法pam
根据以下(对称)距离矩阵tmp
进行聚类:
if(!require("cluster")) { install.packages("cluster"); require("cluster") }
tmp <- matrix(tmp <- matrix(c( 0, 20, 20, 20, 40, 60, 60, 60, 100, 120, 120, 120,
20, 0, 20, 20, 60, 80, 40, 80, 120, 100, 140, 120,
20, 20, 0, 20, 60, 80, 80, 80, 120, 140, 140, 80,
20, 20, 20, 0, 60, 80, 80, 80, 120, 140, 140, 140,
40, 60, 60, 60, 0, 20, 20, 20, 60, 80, 80, 80,
60, 80, 80, 80, 20, 0, 20, 20, 40, 60, 60, 60,
60, 40, 80, 80, 20, 20, 0, 20, 60, 80, 80, 80,
60, 80, 80, 80, 20, 20, 20, 0, 60, 80, 80, 80,
100, 120, 120, 120, 60, 40, 60, 60, 0, 20, 20, 20,
120, 100, 140, 140, 80, 60, 80, 80, 20, 0, 20, 20,
120, 140, 140, 140, 80, 60, 80, 80, 20, 20, 0, 20,
120, 120, 80, 140, 80, 60, 80, 80, 20, 20, 20, 0),
nr=12, dimnames=list(LETTERS[1:12], LETTERS[1:12]))
tmp_pam <- pam(as.dist(tmp, diag = TRUE, upper = TRUE) , k=3)
tmp_pam$clusinfo # get cluster info
tmp_pam$silinfo # get silhouette information
clusplot(tmp_pam)
我在这里阅读了 clusplot
使用cmdscale
和princomp
,这很有意义。 但是,未给出操作顺序。
如何从clusplot
的输出中获取Component1和Component2坐标及其簇标签和点ID? 我想要访问这些文件,以便在ggplot中修改/绘制它们。
我可以推测出绘图与轮廓信息有某种关系,但不太了解我们如何得出以下最终绘图:
根据文档 ,clusplot使用
投影您的数据。 可能取决于您是传递数据还是距离矩阵。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.