我正在使用两列表,试图制作出密度等高线图。 “ HiChIP_VillusvsCrypt”是x轴,“ RNAseq_VillusvsCrypt”是y轴。If you see in this attached image, there is a legend with the density scaling from 0 to 0.2. I would like to be able to play around with this scaling, if possible (i.e. set bounds between 0 and 0.1).我感谢任何建议!
library(ggplot2)
df1 <- data.frame(HNF4_Looping_HiChIPvsRNASeq_VillusvsCrypt$HiChIP_log2FC_VillusvsCrypt, HNF4_Looping_HiChIPvsRNASeq_VillusvsCrypt$RNAseq_log2FC_VillusvsCrypt)
ggplot(df1, aes(df$HNF4_Looping_HiChIPvsRNASeq_VillusvsCrypt.HiChIP_log2FC_VillusvsCrypt, df$HNF4_Looping_HiChIPvsRNASeq_VillusvsCrypt.RNAseq_log2FC_VillusvsCrypt))+
stat_density_2d(aes(fill = ..level.. ), geom = "polygon")+scale_x_continuous(name="HiChIP_VillusvsCrypt", limits=c(-4,4))+scale_y_continuous(name="RNASeq_VillusvsCrypt", limits=c(-4,4))
我无法复制您的示例代码,因此我将用标准数据集替代以说明我的观点。
玩边界只是在颜色/填充上设置限制,并确保oob
参数合适。
假设我们有以下情节。
library(ggplot2)
myplot <- ggplot(faithful, aes(eruptions, waiting)) +
stat_density_2d(aes(fill = after_stat(level)),
geom = "polygon") +
xlim(1, 6) +
ylim(35, 100)
myplot
我们可以按照以下限制进行游戏:
myplot + scale_fill_continuous(limits = c(0, 0.01),
oob = scales::squish)
由reprex package(v0.3.0)在2020-04-15创建
如果要在基础值上设置乘数,则可以如下使用aes()
函数:
aes(fill = after_stat(level * 10))
注意after_stat()
功能需要ggplot2 v3.3.0。较早的版本使用stat()
,甚至较旧的语法也要使用..myvariable..
。