R:heatmap颜色与数据不对应

时间:2016-12-20 09:43:20

标签: r heatmap

我是R的新手并且有关于热图的问题。

我在行和列中列出了不同条件下各自的丰度。该数据被归一化,因此在每一行中有一个代表最大值,其余值在1和0之间。我将1设置为红色,将0设置为白色。

当我使用刻度绘制热图时,我的每一行都没有红色正方形(= 1)。

这是我一直在使用的代码:

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)) 

我还尝试了其他选项,例如:

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

如果您对如何调整它有任何建议,那就太棒了。感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您想要关闭缩放。从?heatmapscale&#34;在行或列方向上居中并缩放值。&#34;

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)

比例等于&#34;列&#34;

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

enter image description here

等于&#34;无&#34;

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

enter image description here