[英]How to get the point coordinates and cluster labels from R clusplot()
I use the k-medoids algorithm pam
to do clustering based on the (symmetric) distance matrix, tmp
, below: 我使用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)
I have read here that clusplot
uses cmdscale
and princomp
, which makes sense. 我在这里阅读了 clusplot
使用cmdscale
和princomp
,这很有意义。 However, the order of the operations is not given. 但是,未给出操作顺序。
How can I get the Component1 and Component2 coordinates, along with their cluster labels and point id's from the output of clusplot
? 如何从clusplot
的输出中获取Component1和Component2坐标及其簇标签和点ID? I want to have access to these in order to modify / plot them in ggplot. 我想要访问这些文件,以便在ggplot中修改/绘制它们。
I can guess the plotting is somehow related to the silhouette information but do not quite understand how we get to the final plot below: 我可以推测出绘图与轮廓信息有某种关系,但不太了解我们如何得出以下最终绘图:
According to the documentation , clusplot uses either 根据文档 ,clusplot使用
to project your data. 投影您的数据。 Probably depends on whether you passed a data or a distance matrix. 可能取决于您是传递数据还是距离矩阵。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.