您无法将颜色设置为特定值,但可以选择非常小的范围,例如[0.999,1.001]
您应该为问题中提到的范围设置分隔符,然后相应地分配颜色;
library(pheatmap)
bk1 <- c(seq(-2,0.9,by=0.1),0.999)
bk1 <- c(1.001,seq(1.1,3,by=0.1))
bk <- c(bk1,bk2) #combine the break limits for purpose of graphing
my_palette <- c(colorRampPalette(colors = c("darkblue", "lightblue"))(n = length(bk1)-1),
"gray38", "gray38",
c(colorRampPalette(colors = c("darkred", "tomato1"))(n = length(bk2)-1)))
pheatmap(df, color = my_palette, breaks = bk, scale = "none",
cluster_rows = F, cluster_cols = F, margin = c(5,5))
我使用以下方法制作了一个示例数据集rnorm.within https://gist.github.com/tomhopper/19f07fc96db8d149b24f:
#V1 is random between -2 and 3
#V2 is equal to 1
#V3 is random between 0 and 3
df <- cbind(rnorm.within(1000, -2, 3),rep(1,1000), rnorm.within(1000,0,3))
这将是上面创建的数据的热图;