R hotmap默认如何排序行?

时间:2015-06-08 09:14:19

标签: r heatmap dendrogram

R heatmap()文档说明RowvColv(即行和列排序参数):

  

如果缺少任何一个,默认情况下,那么相应的树形图的排序是行/列的平均值,即,在行的情况下,Rowv< - rowMeans(x,na.rm = na.rm)。

我认为它就像那样容易,但现在我猜在默认排序算法中必须有更多内容。

让我们有这个相关矩阵:

m = matrix(nrow=7, ncol = 7, c(1,0.578090870728824,0.504272263365781,0.526539138953634,0.523049273011785,0.503296777916728,0.638770769734758,0.578090870728824,1,0.59985543029105,0.663649941610205,0.630998114483389,0.66814547270115,0.596161809036262,0.504272263365781,0.59985543029105,1,0.62468477053142,0.632715952452297,0.599037620726669,0.607925540860012,0.526539138953634,0.663649941610205,0.62468477053142,1,0.7100707346884,0.738094117424525,0.639668277558577,0.523049273011785,0.630998114483389,0.632715952452297,0.7100707346884,1,0.651331659193182,0.64138213322125,0.503296777916728,0.66814547270115,0.599037620726669,0.738094117424525,0.651331659193182,1,0.612326706593738,0.638770769734758,0.596161809036262,0.607925540860012,0.639668277558577,0.64138213322125,0.612326706593738,1))

m
          [,1]      [,2]      [,3]      [,4]      [,5]      [,6]      [,7]
[1,] 1.0000000 0.5780909 0.5042723 0.5265391 0.5230493 0.5032968 0.6387708
[2,] 0.5780909 1.0000000 0.5998554 0.6636499 0.6309981 0.6681455 0.5961618
[3,] 0.5042723 0.5998554 1.0000000 0.6246848 0.6327160 0.5990376 0.6079255
[4,] 0.5265391 0.6636499 0.6246848 1.0000000 0.7100707 0.7380941 0.6396683
[5,] 0.5230493 0.6309981 0.6327160 0.7100707 1.0000000 0.6513317 0.6413821
[6,] 0.5032968 0.6681455 0.5990376 0.7380941 0.6513317 1.0000000 0.6123267
[7,] 0.6387708 0.5961618 0.6079255 0.6396683 0.6413821 0.6123267 1.0000000

heatmap(m)输出为:

enter image description here

行(和列)顺序为:1,3,7,5,2,6,4

但是,我预计订购时间为:

order(rowMeans(m))
1 3 7 2 6 5 4

怎么样?

我想这可能与树状图聚类的方式有关。但仍然不确定:如果我第一组4和6然后可能使用6x6矩阵,其中一行/列是原始行4和6的平均值(?),它仍然不应改变例如行2和5,应该吗?

非常感谢你的提示!

1 个答案:

答案 0 :(得分:2)

heatmap帮助您可以阅读:

  

通常,根据某些组重新排序行和列   价值(行或列意味着)在受到的限制范围内   树形图是在进行的。

事实上,使用Rowmeans / Colmeans的重新排序适用于clustres。这是通过两个步骤在内部完成的。我将在每个步骤中绘制树形图,以显示如何重新调整簇。

hcr <- hclust(dist(m))
ddr <- as.dendrogram(hcr)
plot(ddr)

enter image description here

现在如果你通过rowmenas重新排序树形图,我们得到相同的OP顺序。

Rowv <- rowMeans(m, na.rm = T)
ddr <- reorder(ddr, Rowv)
plot(ddr)

enter image description here

当然,如果您提供新的聚类功能或订单功能,则可以更改此订单。我在这里使用的是默认值:hclustreorder