2017-04-21 201 views
0

我正在嘗試做一個氣泡圖,其中點的顏色是一個漸變的顏色取決於一個值。我設定的極限值是0.0001到0.1。我遇到的問題是,我希望顏色漸變的圖例具有相同的長度,從0.0001到0.001,從0.001到0.01,從0.01到0.1。我寫的代碼在規模中間代表0.5。 我有這樣的:如何將ggplot2中的顏色漸變圖例設置爲給定值?

x <- as.data.frame(cbind(c("rRNA modification","response to hydrogen peroxide","RNA processing","mRNA processing","rRNA modification","response to hydrogen peroxide","RNA processing","mRNA processing"),c("DE","DE","DE","DE","AS","AS","AS","AS"),c(3.42,2.78,1.37,0.83,0,2.87,4.05,8.63),c(4.62e-08,4.32e-03,9.00e-02,8.60e-01,0,5.30e-01,5.67e-03,6.72e-03))) 
colnames(x) <- c("go","set_gene","factor","p.value") 
x$factor<- as.numeric(as.character(x$factor)) 
x$p.value <- as.numeric(as.character(x$p.value)) 
library(ggplot2) 
plot1 <- ggplot(x,aes(x=set_gene,y=go,size=factor,fill=ifelse(p.value>0.1,0.1,ifelse(p.value<0.0001,0.0001,p.value)))) 
plot1 <- plot1+ geom_point(shape=21,size=x$factor*4) 
library(scales) 
plot1<- plot1 + 
scale_fill_gradientn(colours=c("red","orange","yellow","grey90"),values = 
rescale(c(0.0001,0.001,0.01,0.1)),limits=c(0.0001,0.1)) 
plot1 

當前的結果:

enter image description here

期望的結果:

enter image description here

謝謝!

回答

1

如何使用:

plot1<- plot1 + scale_fill_gradientn(name = "p-value", trans = "log", breaks = c(0.0001,0.001,0.01,0.1),limits = c(0.0001,0.1),colours=c("red","orange","yellow","grey90")) 

輸出: enter image description here

相關問題