Pheatmap Color for Specific Value

雨燕双飞 提交于 2019-12-06 13:18:48

You cannot set the color for a specific color but you can go for a very small range like [0.999,1.001]

Should set the breaks to for the specified ranges you mentioned in the question and the assign the colors accordingly;

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))

For purpose of showing an example using rnorm.within function I made the following data-set:

   #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))

And this will be the heatmap for the data created above;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!