plot - R clustering- silhouette with observation labels -
i hierarchical clustering cluster
package in r. using silhouette
function, can silhouette plot of cluster output given height (h) cut-off in dendrogram.
# 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)
this gives figure below, point frustrates me. how can use observation labels rownames(tmp)
in silhouette plot opposed numeric indices (1 12) - make no sense whatsoever me.
i'm not sure why silhouette
call seems drop row names. can add them with
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)
Comments
Post a Comment