Using multiple scales scale_colour_gradient for different data ranges on the same chart

I am very new to R, so please carry me if something is unclear in my question.

I have a data.frame"protein" with 5 columns, namely:

1.protein_name, 2.protein_FC, 3.protein_pval, 4.mRNA_FC, 5.mRNA_pval and 6.freq.

I am trying to plot a volcano with x = log2 (protein_FC), y = -log10 (protein_pval). Then match the size of the dots with the frequency and color of mRNA_FC. All this works great, and here is the code I used:

ggplot( protein [ which ( protein$freq <= 0.05 ),] , aes( x = log2( protein_FC ) ,
       y = -log10 ( protein_pval ) , size = freq , colour = mRNA_FC , 
       label = paste(protein_name,",",mRNA_pval), alpha=1/1000)) + 
  geom_point() + geom_text( hjust = 0 , vjust = 0 , colour = "black" , size = 2.5 ) + 
  geom_abline( intercept = 1.3 , slope = 0) + 
  scale_colour_gradient(limits=c(-3,3))

everything is fine. But due to the nature of the experiment, the data is tight around mRNA_FC = 0. There, the default color scheme used by ggplot does not distinguish different points very well.

, low="colour1" high="colour2". , mRNA_FC, - . -3<mRNA<-0.2, -0.2<mRNA_FC<0, 0<mRNA_FC<0.2 0.2<mRNA_FC<3.

.

. !

+5
1

scale_gradientn. :

library(ggplot2)

x = seq(-0.1, 0.1, len=100)
y = 0:10
dat = expand.grid(x=x, y=y)

ggplot(data=dat, aes(x=x, y=y, fill=x)) +
  geom_raster() +
  scale_fill_gradientn(colours=c('red', 'yellow', 'cyan', 'blue'),
    values   = c(-0.05,-1e-32,1e-32,0.05),
    breaks   = c(-0.05,-0.005,0.005,0.05),
    rescaler = function(x,...) x,
    oob      = identity)

enter image description here

+10

All Articles