Reputation: 21
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!
Upvotes: 2
Views: 2498
Reputation: 5956
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)
df_heatmap <- heatmap(x,
Rowv=NA,
Colv=NA,
col=hm.colors,
scale = "column",
margins = c(5,10))
df_heatmap <- heatmap(x,
Rowv=NA,
Colv=NA,
col=hm.colors,
scale = "none",
margins = c(5,10))
Upvotes: 1