How to arrange column in heatmap.2() based on a predefined order

Viewed 19513

The following code

 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);

Generate a heat map that looks like this:

enter image description here

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?

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);
1 Answers
Related