R 热图着色取决于高于或低于零的值
我正在尝试在 R 中制作热图,其中我的数据范围从 -5 到 +50。我希望 0 的值是白色,0 到 -5 之间的值从白色到蓝色渐变着色,0 到 +50 之间的值从白色到红色着色。理想情况下,我还希望使用相同的缩放比例,即 -5 时的蓝色暗度与 +5 时的红色暗度相同。
我有热图的工作代码,整个数据集的渐变从蓝色到红色,白色着色点接近数据的平均值。
hv <- heatmap.2(data_matrix,
scale="none",
Rowv=NA,
Colv=NA,
col = rev(brewer.pal(11,"RdBu")),
margins=c(5,5),
cexRow=0.5, cexCol=1.0,
ylab= "Mutations",
main = "heatmap",
key=TRUE,keysize=1.5, trace="none")
任何建议将不胜感激。
干杯!
I am trying to make a heatmap in R where my data ranges from -5 to +50. I would like values of 0 to be white, the values between 0 and -5 to be coloured on a gradient from white to blue and the values between 0 and +50 to be coloured from white to red. Ideally, I'd also like the same scaling to be used, i.e. the darkness of blue at -5 to be the same as the darkness of the red at +5.
I have working code for heatmap with the gradient for the whole data set from blue to red with white colouring points close to the mean of the data.
hv <- heatmap.2(data_matrix,
scale="none",
Rowv=NA,
Colv=NA,
col = rev(brewer.pal(11,"RdBu")),
margins=c(5,5),
cexRow=0.5, cexCol=1.0,
ylab= "Mutations",
main = "heatmap",
key=TRUE,keysize=1.5, trace="none")
Any suggestions would be greatly appreciated.
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将这些添加到您的函数中。
中断 = c(5/6* -5,5/6* -4,5/6* -3,5/6* -2,5/6* -1,0,5/6* 1,50/6 *1,50/6*2,50/6*3,50/6*4,50/6*5)
Breaks=breaks
这指定您在热图中使用的中断。
您可以尝试稍微捏造一下数字,并且可以添加更多颜色和中断,中断的数量应该是颜色数 + 1。
给出:
You need to add these to you function.
breaks = c(5/6* -5,5/6* -4,5/6* -3,5/6* -2,5/6* -1,0,5/6* 1,50/6*1,50/6*2,50/6*3,50/6*4,50/6*5)
breaks=breaks
This specifies the breaks you use in the heatmap.
You might try to fudge the numbers a bit, and mayby add a few more colors and breaks, the number of breaks should be number of colors + 1.
Giving this:
如果您的数据从 -5 到 +50,正负值具有相同的渐变将使负颜色看起来几乎全是白色,
相反,完整的色调版本是这样的,
If your data goes from -5 to +50, having the same gradient for positive and negative values will make the negative colours look pretty much all white,
In contrast, the full hue version goes like this,