R聚类-带观察标签的轮廓

R聚类-带观察标签的轮廓,r,plot,cluster-analysis,R,Plot,Cluster Analysis,我使用R中的cluster包进行分层聚类。使用剪影功能,我可以获得树状图中任何给定高度(h)截止值的聚类输出剪影图 # run hierarchical clustering if(!require("cluster")) { install.packages("cluster"); require("cluster") } tmp <- matrix(c( 0, 20, 20, 20, 40, 60, 60, 60, 100, 120, 120, 120,

我使用R中的
cluster
包进行分层聚类。使用
剪影
功能,我可以获得树状图中任何给定高度(h)截止值的聚类输出剪影图

# run hierarchical clustering
if(!require("cluster")) { install.packages("cluster");  require("cluster") } 
tmp <- matrix(c( 0,  20,  20,  20,  40,  60,  60,  60, 100, 120, 120, 120,
                 20,   0,  30,  50,  60,  80,  40,  80, 120, 100, 140, 120,
                 20,  30,   0,  40,  60,  80,  80,  80, 120, 140, 140,  80,
                 20,  50,  40,   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]))

cl <- hclust(as.dist(tmp,diag = TRUE, upper = TRUE), method= 'single')
sil_cl <- silhouette(cutree(cl, h=25) ,as.dist(tmp), title=title(main = 'Good'))
plot(sil_cl)
#运行分层群集
if(!require(“cluster”){install.packages(“cluster”);require(“cluster”)}

tmp我不知道为什么,但是
剪影
调用似乎删除了行名。您可以使用

cl <- hclust(as.dist(tmp,diag = TRUE, upper = TRUE), method= 'single')
sil_cl <- silhouette(cutree(cl, h=25) ,as.dist(tmp), title=title(main = 'Good'))

rownames(sil_cl) <- rownames(tmp)

plot(sil_cl)

cl我发现将参数
cex.names=par(“cex.axis”)
添加到
plot()
函数中可以得到所需的标签:

cl <- hclust(as.dist(tmp,diag = TRUE, upper = TRUE), method= 'single')
sil_cl <- silhouette(cutree(cl, h=25) ,as.dist(tmp), title=title(main = 'Good'))


plot(sil_cl, ces.names = par("cex.axis"))

cl您可以通过添加一些示例输入数据来创建此示例。“约翰·马尔科维奇”的价值观从何而来?@flick先生,完成了,我懒得希望有人知道答案而不必与代码搏斗。