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:
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);
heatmap for a predetermined order of rows. Simply reorder the rows of your second matrix to match the first one, then use for example R's heatmap() function setting Rowv=FALSE to prevent it from automatically reordering the rows, alternatively, you could set Rowv to a vector defining the order.
The heatmap. 2 function from the gplots package allows to produce highly customizable heatmaps. Useful arguments include: Rowv, Colv : process clustering of columns or rows (default TRUE to both)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With