I have RNA-Seq data that I want to visualize in a HeatMap with HeatMap.2 in R, but I do not understand to to force the HeatMap to look the way I want it to.
I have search online a lot and I feel like I am very close, but cannot overcome the last hurdle. I am using the following code where I have a matrix with 6 samples (triplicates of 2 conditions) and 209 specific genes I want to look at. The 209 genes I'm interested in fit into 3 categories, and I'm trying to show that using the RowSideColors=
argument.
Here is my code:
colors <- colorpanel(75,"yellow","black","dodgerblue2")
heatmap.2(as.matrix(counts),
col=colors,
RowSideColors=SideCol,
scale="row",
key=T,
keysize=1,
density.info="none",
trace="none",
cexCol=0.9,
cexRow=0.5)
I know from searching online that I can use the Rowv command to reorder the dendrogram and order the rows the way I want, but I don't understand how to use the command. When I set Rowv=F
it does not make a dendrogram and my genes are ordered the same as they are in the matrix. I want them to be grouped by RowSideColor category and then arranged such that they follow the key (i.e. all blue rows together and fade into black then yellow).
I thought I could get around this obstacle by determining the row z-score myself and arranging my matrix by category and row z-score, but my z-score calculations were much different than what Heatmap.2 determines, and the row color scale follows no pattern. I determined z-score by (x-mean)/sd
How can I arrange the rows the way I want them to be?
Thanks in advance for any help, I greatly appreciate it!
EDIT:
This is a crude representation of what I'd like the HeatMap to look like: