1

我有多个类似于以下的热图:

X <- matrix(nrow=3, ncol=3)
X[1,] <- c(0.3, 0.4, 0.45)
X[2,] <- c(0.3, 0.7, 0.65)
X[3,] <- c(0.3, 0.4, 0.45)
colnames(X)<-c(1.5, 3, 4)
rownames(X)<-c(1.5, 3, 4)
library(gplots)

heatmap.2( X, Rowv=NA, Colv=NA, col=rev(heat.colors(256)), 
           sepcolor="black", trace="none",dendrogram="none" )

现在,为了使这种多张图看起来更相似,我怎样才能让左上角的直方图总是介于 0 和 1 之间?


根据 yuk 的回答,我制作了这个版本:

X <- matrix(nrow=3, ncol=3)
X[1,] <- c(0.3, 0.4, 0.45)
X[2,] <- c(0.3, 0.7, 0.65)
X[3,] <- c(0.3, 0.4, 0.45)
colnames(X)<-c(1.5, 3, 4)
rownames(X)<-c(1.5, 3, 4)
library(gplots)

colors <- rev(heat.colors(256))

colbr <- c(seq(0, 1, len=length(colors)+1))
heatmap.2(X, scale="none", col=colors, breaks=colbr,
          key=T, symkey=F, density.info="histogram", trace="none", Rowv=NA, Colv=NA, 
          sepcolor="black", dendrogram="none" )

现在色阶在 0 和 1 位之间,直方图仍然没有。在此处输入图像描述

4

1 回答 1

0

我认为最好的方法是设置颜色中断。

这是我通常做的(x是热图的矩阵):

n.col=16 # number of colors
cm = redblue(n.col) # red-white-blue colormap
mmx = min(abs(min(x)),abs(max(x))) # find min value, or you can set to a number
colbr <- c(seq(-mmx/2,mmx/2, len=length(cm)+1)) # vector of symmetric breaks
heatmap.2(x, scale="none", col=cm, breaks=colbr,
          key=T, symkey=F, density.info="histogram", trace="none")
于 2013-08-28T21:56:06.637 回答