hierarchical cluster labeling with plots

妖精的绣舞 提交于 2019-12-08 00:04:12

问题


I have a distance matrix for ~20 elements, which I am using to do hierarchical clustering in R. Is there a way to label elements with a plot or a picture instead of just numbers, characters, etc?

So, instead of the leaf nodes having numbers, it'd have small plots or pictures.

Here is why I'm interested in this functionality. I have 2-D scatterplots like these (color indicates density)

http://www.pnas.org/content/108/51/20455/F2.large.jpg (Note that this is not my own data)

I have to analyze hundreds of such 2-D scatter plots, and am trying out various distance metrics which I'm feeding on to hclust. The idea is to quickly (albeit roughly) cluster the 2-D plots to figure out the larger patterns, so we can minimize the number of time-consuming, follow-up experiments. Hence, it'll be ideal to label the dendrogram leaves with the appropriate 2-D plots.


回答1:


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.



来源:https://stackoverflow.com/questions/13850896/hierarchical-cluster-labeling-with-plots

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