2
votes

I am new to R and have a question about heatmaps.

I have a list of proteins on the rows and in the columns their respective abundance in different conditions. This data are normalized, so in each row there is a 1 standing for the maximum and the rest of the values are between 1 and 0. I set 1 as red and 0 as white.

When I plot the heatmap with a scale though, I don't have a red square (=1) in each row, as it should be.

This is the code I have been using:

df <- read.table("my_data.txt", header = TRUE)
row.names(df) <- df$name
df <- df[, 2:21]
df_matrix <- data.matrix(df)
breaks = seq(0, max(df), length.out = 1000)
gradient1 = colorpanel( sum( breaks[-1]<=1 ), "white", "red" )
gradient2 = colorpanel( sum( breaks[-1]>1), "black", "red")
hm.colors = c(gradient1, gradient2)
df_heatmap <- heatmap(df_matrix, 
                  Rowv=NA, 
                  Colv=NA, 
                  col=hm.colors, 
                  scale = "column", 
                  margins = c(5,10)) 

I also tried other options, like:

df_heatmap <- heatmap(df_matrix, 
                  Rowv=NA, 
                  Colv=NA, 
                  col=heat.colors(256),
                  scale = "column", 
                  margins = c(5,10)) 

If you have any suggestion on how to adjust it, it would be great. Thank you for the help!

1
Welcome to SO!, could you please use dput(head(df)) to post a subset of your dataset and also the output image so that your problem is reproducibleSilence Dogood
You can test heatmaps from the ggplot2 packageMateusz1981

1 Answers

1
votes

You want to turn scaling off. From ?heatmap, scale "centers and scales values in either the row or column direction."

x <- matrix(rnorm(100), nrow=10)
x <- apply(x, 1, function(z) abs(z)/(max(z)))

breaks = seq(0, max(x), length.out = 1000)
gradient1 = colorpanel( sum( breaks[-1]<=1 ), "white", "red" )
gradient2 = colorpanel( sum( breaks[-1]>1), "black", "red")
hm.colors = c(gradient1, gradient2)

Scale equals "column"

df_heatmap <- heatmap(x, 
                      Rowv=NA, 
                      Colv=NA, 
                      col=hm.colors, 
                      scale = "column", 
                      margins = c(5,10)) 

enter image description here

scale equals "none"

df_heatmap <- heatmap(x, 
                  Rowv=NA, 
                  Colv=NA, 
                  col=hm.colors, 
                  scale = "none", 
                  margins = c(5,10))

enter image description here