在一个绘图中对不同范围的数据使用多个scale_colour_gradient比例 [英] Using multiple scale_colour_gradient scales for different ranges of the data in one plot
问题描述
我有一个含有5列的 data.frame
protein,即;
1.protein_name,2.protein_FC,3.protein_pval,4.mRNA_FC,5.mRNA_pval和6.freq。
我想绘制一个x = log2(protein_FC),y = -log10(protein_pval)的火山图。然后将点的大小映射到频率和颜色到mRNA_FC。这一切都正常工作,这里是我已经使用的代码:
$ $ $ p $ g $ pggplot(protein [which(protein $ freq <= 0.05),],aes(x = log2(protein_FC),
y = -log10(protein_pval),size = freq,color = mRNA_FC,
label = paste(protein_name,,,mRNA_pval), alpha = 1/1000))+
geom_point()+ geom_text(hjust = 0,vjust = 0,color =black,size = 2.5)+
geom_abline(截距= 1.3,斜率= 0 )+
scale_colour_gradient(limits = c(-3,3))
一切正常直到这里。但由于实验的性质,数据在 mRNA_FC = 0
附近是相当密集的。在那里,ggplot应用的默认配色方案在区分不同点方面效果不佳。
我已经尝试过使用 但我还没有找到任何方法。 任何帮助将不胜感激。 对于这种类型的事情,您想使用 I am very new to R so please bear with me if something is not clear in my question. I have a 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 plot with x=log2(protein_FC), y=-log10(protein_pval). Then map the size of the dots to freq and colour to mRNA_FC. This all works fine and here is the code that I have used: all is fine till here. But because of the nature of the experiment, data it is quite dense around I have tried various colour scales by using But I havent found any way of doing it yet. Any help would be appreciated.
Cheers! For this type of thing you want to use 这篇关于在一个绘图中对不同范围的数据使用多个scale_colour_gradient比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! low = colour1
和 high =colour2
。不过,我认为最好在 mRNA_FC
范围内使用多个色阶,即类似。对于 -0.2
-3
干杯! 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(colors = 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)
data.frame
"protein" with 5 columns, namely;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))
mRNA_FC = 0
. There, the default colour scheme that ggplot applies doesnt work very well in distinguishing different points.low="colour1"
and high="colour2"
. However I think it will be best to use multiple colour scales over the ranges of mRNA_FC
, i.e. something like. blue to white for -3<mRNA<-0.2
, red to white for -0.2<mRNA_FC<0
, green to white for 0<mRNA_FC<0.2
and black to white for 0.2<mRNA_FC<3
. scale_gradientn
. For example: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)