0

I am trying to show the colors for each row in my matrix (min to max gradient):

 [1,]  8 12   11  5   24
 [2,]  1  2    7  0    8
 [3,] 53 99 1501 15 9859
 [4,] 59 24   19 19   32
 [5,]  4  2   11  0   68
 [6,]  4  9  177  2  710
 [7,]  2  1    2  2    3
 [8,]  0  5  133  0 2195
 [9,]  3  3    2  1   15
[10,]  0  1    0  0   14
[11,]  0  3   21  0   17
[12,]  2  1    2  0    6
[13,] 11 26   22  3   16
[14,]  6 38  217  1  354
[15,]  3 10   17  0   68
[16,]  3  3   12  2   19
[17,]  7  5   26  1   40
[18,]  1  0    6  0   27
[19,]  1  0   37  0  434
[20,] 30 15   20  9   27

My code is as follows:

RT<-read.table("tmp",header=FALSE,sep="\t");
mat <-data.frame(RT)
pheatmap(mat, scale = "row",cluster_cols=FALSE,cluster_rows = FALSE, row.names =FALSE);
dev.off()

I have received the following image: enter image description here

As you can see in the 2nd row the max needs to be red but it is orange because column 3 and 5 of the 2nd row have similar values. I want to do max is red, min is blue, and gradient between red,yellow and blue, for the values between max and min for each row independently. 0's always be blue. Only identical values should get the same color. I have tried other solutions from R: Row scaling not working correctly for heatmap but that didn't work for me. Please help.

Process1
  • 478
  • 1
  • 3
  • 12

1 Answers1

0

I tried a few things and I think I may have an answer that is close:

A) divide each row with its max.

 xx <- apply(mat,1, function(i) i/max(i));

B) minimum is always 0. So, I converted the minimum of each row to 0.

xx1<-t(apply(xx, 1, function(x) replace(x, x== min(x), 0.0)))
pheatmap(xx1, scale = "none",cluster_cols=FALSE,cluster_rows = FALSE, row.names =FALSE);
dev.off()

This seems to be working but it can be done better.enter image description here

Process1
  • 478
  • 1
  • 3
  • 12