特定值的谱图颜色 [英] Pheatmap Color for Specific Value
问题描述
我对R很陌生,最近我一直在使用pheatmap库来生成热图.我的问题是我想以特定方式为我的热图着色.我将在下面描述:
I am very new to R and recently I have been playing around with the pheatmap library to generate, well, heatmaps. My problem is that I want to color my heatmap in a specific way. I'll describe below:
- 值< 1应该是颜色渐变(例如,深蓝色到浅蓝色)
- 精确等于1的值应该是深灰色
- 值> 1应该是一个颜色渐变(例如,深红色到浅红色)
我在各种调色板上都使用了breaks
参数和color
参数,但是我似乎无法找到一个好的解决方案.我最接近的是这样的:
I have played around with the breaks
parameter and the color
parameter with various palettes but I can't seem to nail a good solution. the closest I've come is something like this:
pheatmap(mtx,
color = c('#4444FF','#F4FF4F','#FF4444'),
breaks = c(0,1,2,3),
legend_breaks = c(0,1,2) )
但是这不允许可视化范围,即0.1应该看起来不同于0.9的阴影,即使它们都应该是蓝色.谁能提供建议或意见?我确实查看了这张票证,并考虑将1更改为NA,但是对于它来说有点太复杂了我.更不用说我不得不关闭针对作弊图的聚类,这不是我希望做的事情.谢谢!
But this doesn't allow for visualization of the ranges, i.e. 0.1 should look a different shade than 0.9 even though they should both be blue. Can anyone provide suggestions or advice? I did look at This ticket and consider changing 1 to NA, but it's a bit too complex for me. Not to mention I'd have to turn off clustering for pheatmap which is not something I wish to do. Thanks!
推荐答案
您不能为特定颜色设置颜色,但是可以使用很小的范围,例如[0.999,1.001]
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))
出于演示目的,使用 rnorm.within
函数,我进行了以下数据设置:
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;
这篇关于特定值的谱图颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!