如何根据预定义的顺序排列 heatmap.2() 中的列 [英] How to arrange column in heatmap.2() based on a predefined order

查看:78
本文介绍了如何根据预定义的顺序排列 heatmap.2() 中的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码

 library("gplots")
 mydata <- mtcars
 hclustfunc <- function(x) hclust(x, method="complete")
 distfunc <- function(x) dist(x,method="euclidean")

 heatmap.2(as.matrix(mydata),dendrogram="row",trace="none", margin=c(8,9), hclust=hclustfunc,distfun=distfunc);

生成如下所示的热图:

请注意,在该图中,该列是由函数自动排序的

Note that in that figure the column is ordered automatically by the function

cyl am vs carb wt drat gear gseq mpg hp dsp

我想做的是创建相同的热图,但与我个人定义的列顺序:

What I want to do is to create the same heatmap but with my personally defined column order:

cn <- c("wt","qsec","vs","am","gear","carb", "mpg","cyl","disp","hp","drat" )

我怎样才能做到这一点?

How can I achieve that?

我尝试像这样使用 Colv 但失败了:

I tried using Colv like this but failed:

heatmap.2(as.matrix(mydata),Colv=cn,dendrogram="row",trace="none", margin=c(8,9), hclust=hclustfunc,distfun=distfunc);

推荐答案

我确实同意帮助页面并不完全清楚,但经过一些实验后我发现您可以使用 FALSE 阻止列排序并将列排序在输入的时间.看到是这样,帮助页面没有任何错误.

I do agree the help page wasn't entirely clear, but after a bit of experimentation I discovered that you could prevent column ordering with FALSE and order the columns at the time of input. After seeing this to be the case, the help page was not wrong in any respect.

heatmap.2(as.matrix(mydata[,cn]), Colv=FALSE, 
          dendrogram="row",trace="none", margin=c(8,9), 
          hclust=hclustfunc,distfun=distfunc)

这篇关于如何根据预定义的顺序排列 heatmap.2() 中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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