用图进行分层聚类标记 [英] hierarchical cluster labeling with plots

查看:169
本文介绍了用图进行分层聚类标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个约20个元素的距离矩阵,用于在R中进行层次聚类.有没有一种方法可以用图形或图片来标记元素,而不仅仅是数字,字符等?

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 (请注意,这不是我自己的数据)

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. 使用 as.dendrogram
  2. 转换您的习惯
  3. 使用 dendrapply 通过树应用功能.该功能可自定义叶子.
  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")

如果尝试自定义节点标签以将其映射到url链接.因此,当您单击叶子名称时,您将导航到其图像.我认为这并不难.

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.

这篇关于用图进行分层聚类标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆