R:居中热图.2键(gplots包)

时间:2012-04-06 19:52:34

标签: r heatmap

我想通过heatmap.2()命令创建一个热图,其中一个颜色键以0为中心(即白色 - > 0,红色 - >>大于0,蓝色 - >小于0)同时保持scale =“none”,因为我有兴趣绘制实际值的热图。但是,使用以下行时,我的所有热图都不以零为中心:

library(gplots)
outputHeatmap <- heatmap.2(heatmapInputActual, dendrogram="none", Rowv=FALSE,
    Colv=FALSE, col= bluered(256), scale="none", key=TRUE, density.info="none", 
    trace="none", cexRow=0.125, cexCol=0.125, symm=FALSE, symkey=TRUE)

我认为使用命令symkey = TRUE会起作用,但事实并非如此。我正在尝试的变量是一个(n×3)数值矩阵的热图。上面描述的heatmap.2()命令有问题的输入如下:

8.408458  5.661144   0.00000000
4.620846  4.932283  -0.46570468
-4.638912 -3.471838  -0.12146109
-4.822829 -3.946024   0.06403327
3.948832  4.520447  -0.31945941

感谢您的时间。我期待着你的回复。

1 个答案:

答案 0 :(得分:10)

解决方案似乎只是将symbreaks添加到您的heatmap.2。以下是您的数据完全可重现的示例:

library(gplots)
#read your example data
heatmapInputActual <- read.table(textConnection(
"8.408458 5.661144 0.00000000
4.620846 4.932283 -0.46570468
-4.638912 -3.471838 -0.12146109
-4.822829 -3.946024 0.06403327
3.948832 4.520447 -0.31945941
"),as.is=TRUE)
#convert sample data to matrix
heatmapInputActual <- as.matrix(heatmapInputActual)
#just add symbreaks to the end of your code
heatmap.2(heatmapInputActual, dendrogram="none", Rowv=FALSE, Colv=FALSE, 
          col = bluered(256), scale="none", key=TRUE, density.info="none", 
          trace="none", cexRow=0.125, cexCol=0.125, symm=F,symkey=T,symbreaks=T)

enter image description here