I'm working with a two column table that I am trying to make a density contour plot out of. "HiChIP_VillusvsCrypt" is the x axis and "RNAseq_VillusvsCrypt" is the y axis. 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). I appreciate any advice!
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))
I can't reproduce your example code, so I'll substitute with a standard dataset to illustrate my points.
Playing with the bounds simply setting the limits on a colour/fill and making sure the
oobargument is appropriate.Let's say we have the following plot.
We can play around with the limits as follows:
Created on 2020-04-15 by the reprex package (v0.3.0)
If you want to set a multiplier on the underlying values, you can use the
aes()function as follows:Note that the
after_stat()function requires ggplot2 v3.3.0. Earlier versions usestat()or even older syntax is to use..myvariable...