0

Heatmap with high expression values on the bottom

I'm quite new to Rstudio and I'm trying to make a heatmap using the heatmaply function in r, but in some heatmaps (with different data) the high expression values (in red) show on top, and with another dataset the high expression values show up at the bottom, with low expression values on top, as in the image.

I use the same code for the different datasets

heatmaply(Heatmap_DEXFORM, dendrogram = "row", scale_fill_gradient_fun = scale_fill_gradient2(low="blue",high="red", midpoint=0,limits=c(-4,6))

Is this a result of the way my data is shaped? Is there a command where I can make the heatmap flip so the high expression values show on top, as in my other heatmaps?

Thanks in advance!

1 Answers1

1

heatmaps are typically ordered based on hierarchical clustering rather than the magnitude of the values. To order based on magnitude (high at the top or vice versa) you would need to supply a dendrogram (as Tal suggested) or manually re-order your data (for example, based on the row sums or row means (or column sums/means)).

See the toy example below.

mat <- scale(mtcars)
heatmaply(mat, dend = "none")
heatmaply(mat[order(rowSums(mat)), ], dend = "none")
alan ocallaghan
  • 3,116
  • 17
  • 37