0

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)

And the output of my HeatMap looks like this

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:

lozzib
  • 5
  • 2
  • Tell me if I'm wrong. You try to group 209 into 3 categories, I see 3 colors red, green blue and in addition to this you want to order them by difference (such as fold change) between two groups - WT and KO. Could you tell me more precisely what result do you expect, I think I had same problem in the past, however I need more information from you. I think the function orders by Z-score, there are differences in values, however we don't see them in colors... Side colors are ordoered accorrdong to dendrogram – Adamm Aug 24 '18 at 12:07
  • @Adamm Yes, this is essentially what I want to do. I edited the question to include an example of what I want the HeatMap to look like. At this point I am less concerned with the row dendrogram so I am willing to loose it to order my samples the way I want. – lozzib Aug 24 '18 at 19:28
  • To be honest it might be hard to get by one run of the function. You'll propably need a complex `ggplot` function to obtain desired result. However it's other solution. Advices I can give: Create three different heatmaps (corresponding 3 side colors) - so you need 3 datasets. Calculate logFC of each gene in each dataset and order by it. Then create 3 heatmaps which may be combined in one sheet using `grid` one by one. Something like [this](https://stackoverflow.com/questions/15114347/to-display-two-heatmaps-in-same-pdf-side-by-side-in-r) – Adamm Aug 27 '18 at 05:18
  • 1
    @Adamm This will work!! Thank you so much!! I can't believe I just needed to sort by foldchage to get the order I wanted !!!! – lozzib Aug 27 '18 at 21:11

0 Answers0