我在R中使用heatmap2功能。我为不同的矩阵创建热图,最后我想比较它们。我已经定义了我的颜色托盘,我使用相同颜色的托盘对于不同的矩阵,但问题是绘制后的颜色键间隔对于不同的热图是不同的(一个是从-0.2到0.2而另一个是从-0.15到0.2)并且它们不是真正可比的。 有人会帮我解决这个问题吗? 这是我的努力:
colors = c(seq(min(Gold),-0.0002,length=100),seq(-0.0003,0.0002,length=20),seq(0.0003,max(Gold),length=100))
my_palette <- colorRampPalette(c("blue","green","white","yellow", "red"))(n = 219)
# Creat heatmap for two matrices:
pdf("Gold1.pdf")
heatmap.2(Gold,Colv=as.dendrogram(hcr),Rowv=as.dendrogram(hc), col=my_palette, scale="none" , key=TRUE, symkey=FALSE, symm=F,symbreaks=T,cexRow=1,cexCol=1,margins=c(6,11),labRow = "" ,trace="none",keysize = 1.2,density.info="none",main="Ground truth",srtCol=90)
heatmap.2(mtlcof,Colv=as.dendrogram(hcr),Rowv=as.dendrogram(hc), col=my_palette, scale="none" , key=TRUE, symkey=FALSE, symm=F,symbreaks=T,cexRow=1,cexCol=1,margins=c(6,11),labRow = "" ,trace="none",keysize = 1.2,density.info="none",main="MTL",srtCol=90)
dev.off()
答案 0 :(得分:0)
您可以使用breaks
参数:
library(gplots)
Gold <- matrix(runif(300, -0.15, 0.2), ncol=15)
colors = c(seq(min(Gold),-0.0002,length=100),seq(-0.0003,0.0002,length=20),seq(0.0003,max(Gold),length=100))
my_palette <- colorRampPalette(c("blue","green","white","yellow", "red"))(n = 219)
my_breaks <- seq(-0.2, 0.2, length.out=length(my_palette)+1)
heatmap.2(Gold, col=my_palette, breaks=my_breaks)