hierarchical cluster labeling with plots

喜你入骨 提交于 2019-12-06 08:37:38

There is one option :

  1. Convert your hclust using as.dendrogram
  2. use dendrapply to apply a function through the tree. The function customize the leaf.

here one example , where I color my cluster and I change the chape of the node.

hc = hclust(dist(mtcars[1:10,]))
hcd <- as.dendrogram(hc)
mycols <- grDevices::rainbow(attr(hcd,"members"))
i <- 0 
colLab <- function(n) {
    if(is.leaf(n)) {
      i <<- i + 1
      a <- attributes(n)
      attr(n, "nodePar") <-
        c(a$nodePar, list(lab.col = mycols[i],lab.bg='grey50',pch=sample(19:25,1)))
      attr(n, "frame.plot") <- TRUE
    }
    n
  }
clusDendro = dendrapply(hcd, colLab)
# make plot
plot(clusDendro, main = "Customized Dendrogram", type = "triangle")

Idea:

If you try to customize the node label to an map it to an url link. So when you click on the leaf name , you navigate to its image. I think it is not hard to do.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!