作者:渴求打怪升级 | 来源:互联网 | 2023-02-04 15:49
我在中创建了一个热图,并ggplot2
使用geom_tile
映射了值scale_fill_gradientn
。色标分为两个渐变。一个梯度将值从0映射到0.05,另一个梯度将值从0.05映射到1。我希望红黄色渐变(0-0.05)具有与黑褐色渐变(0.05-1)相同的高度。
问题:如何修改颜色条,以使值0.05位于条的中间/中央,从而使两个不同的颜色渐变的高度相同?
换句话说,假设0.05刻度线是一个滑块,您可以将其移动到扩展/压缩各个渐变的条的中间。
以下两篇文章讨论了类似的问题,但没有最终解决方案,或者至少没有我可以轻易理解并回答我的问题的解决方案:
类似问题1
类似的问题2
非常感谢大家阅读我的问题并思考可能的解决方案。到目前为止,除了在Photoshop中编辑颜色栏外,我什么都找不到。彼得
可重现的示例:
TEST <- read.csv ("https://filetea.me/n3wHRhuy0GlS4xvjQDxs95BVA",header=T,row.names=NULL)
library(ggplot2)
ggplot(TEST, aes(x=Measure, y=SMTSD))+
geom_tile(aes(fill=Pval),colour="grey50", size=0.1) +
scale_x_discrete(expand = c(0,0))+
coord_equal(ratio=1)+
scale_fill_gradientn(colours=c("red","yellow","black","#996633"),
values=c(0,0.0499,0.05,1),
na.value="white", guide="colourbar",
name="P-value",limits=c(0,1),breaks=c(0,0.05,1))+
guides(fill = guide_colourbar(barheight = 20, direction = "vertical",
title.position="top", title.hjust = 0.5,title.vjust = 0.5, nbin = 50))
Adam Quek..
5
更改scale_fill_gradient值和中断将为您提供所需的内容:
ggplot(TEST, aes(x=Measure, y=SMTSD))+
geom_tile(aes(fill=Pval^0.2313782),colour="grey50", size=0.1) +
scale_x_discrete(expand = c(0,0))+
coord_equal(ratio=1)+
scale_fill_gradientn(colours=c("red","yellow","black","#996633"),
values=c(0,0.0499,0.05,1)^ 0.2313782,
na.value="white", guide="colourbar",
name="P-value",limits=c(0,1),breaks=c(0,0.05,1)^ 0.2313782,
labels=c(0,0.05,1))+
guides(fill = guide_colourbar(barheight = 20, direction = "vertical",
title.position="top", title.hjust = 0.5,title.vjust = 0.5, nbin = 50))
用新图像编辑的ps
1> Adam Quek..:
更改scale_fill_gradient值和中断将为您提供所需的内容:
ggplot(TEST, aes(x=Measure, y=SMTSD))+
geom_tile(aes(fill=Pval^0.2313782),colour="grey50", size=0.1) +
scale_x_discrete(expand = c(0,0))+
coord_equal(ratio=1)+
scale_fill_gradientn(colours=c("red","yellow","black","#996633"),
values=c(0,0.0499,0.05,1)^ 0.2313782,
na.value="white", guide="colourbar",
name="P-value",limits=c(0,1),breaks=c(0,0.05,1)^ 0.2313782,
labels=c(0,0.05,1))+
guides(fill = guide_colourbar(barheight = 20, direction = "vertical",
title.position="top", title.hjust = 0.5,title.vjust = 0.5, nbin = 50))
用新图像编辑的ps