默认情况下,R热图如何排序行? [英] How does R heatmap order rows by default?

查看:894
本文介绍了默认情况下,R热图如何排序行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The R heatmap() documentation says for Rowv and Colv (i.e. row and column ordering parameters):

如果默认情况下缺少其中任何一个,则相应的树状图的排序方式为行/列的平均值,即,在行的情况下,Rowv<-rowMeans(x,na.rm = na.rm).

If either is missing, as by default, then the ordering of the corresponding dendrogram is by the mean value of the rows/columns, i.e., in the case of rows, Rowv <- rowMeans(x, na.rm = na.rm).

我认为这很容易,但是现在我想默认排序算法中还必须包含更多内容.

I thought it's as easy as that but now I guess there must be something more in the default ordering algorithm.

让我们有这个相关矩阵:

Let's have this correlation matrix:

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)输出为:

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

The row (and column) order is: 1, 3, 7, 5, 2, 6, 4

但是,我希望订购的顺序是:

However, I expected the ordering to be:

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

那怎么样?

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

I guess it could have something to do with how the dendrograms are clustered. But still unsure: if I first group 4 and 6 and then perhaps work with a 6x6 matrix where one row/column is the averages(?) of the original rows 4 and 6, it still shouldn't change the mutual order of e.g. rows 2 and 5, should it?

非常感谢您提供任何提示!

Thank you very much for any hint!

推荐答案

heatmap帮助中,您可以阅读:

From heatmap help you can read:

通常,根据一组 值(行或列均值)在 进行树状图.

Typically, reordering of the rows and columns according to some set of values (row or column means) within the restrictions imposed by the dendrogram is carried out.

实际上,使用Rowmeans/Colmeans进行的重新排序已应用于集群.这是通过2个步骤在内部完成的.我将在每个步骤中绘制树状图,以显示如何调整群集.

In fact the reorder using Rowmeans/Colmeans is applied to the clustres. This is done internally in 2 steps. I will plot the dendogramm in each step to show how clusters are reordred.

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

现在,如果按行菜单对树状图进行重新排序,我们将获得相同的OP顺序.

Now If you reorder the dendrogram this by rowmenas we get the same OP order.

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

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

Of course this order can be changed , if you provide a new Clustering function or order function. Here I am using the default ones : hclust and reorder.

这篇关于默认情况下,R热图如何排序行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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