Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何为不同的矩阵确定heatmap2中的颜色间隔?_R - Fatal编程技术网

R 如何为不同的矩阵确定heatmap2中的颜色间隔?

R 如何为不同的矩阵确定heatmap2中的颜色间隔?,r,R,我在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

我在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()
colors=c(seq(最小值(金色),-0.0002,长度=100),seq(-0.0003,0.0002,长度=20),seq(0.0003,最大值(金色),长度=100))

我的调色板您可以使用
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)
库(gplots)
黄金