2017-02-15 27 views
0

我想讓我的數據點等於0出現在x軸上,並避免由軸切割數據點。 我也想保持原來的狀態(對於兩個軸同樣爲0)。如何使數據點等於0出現在使用ggplot的座標軸上?

Here is my graph:

我用這個得到的原點爲0,並設置我的軸​​線的界限:

scale_y_continuous(limits = c(0, 40), expand = c(0, 0))+ 
scale_x_continuous(limits = c(0, 30), expand = c(0, 0)) 

如果我改變Y的用於

scale_y_continuous(limits = c(-1, 40)) 

限制它也改變了原點...

這是我的代碼,以防萬一你需要它:

require(ggplot2) 
myplot<-ggplot(data=NULL,aes(x = Length, y = Complete)) + 
geom_point(data = C,shape=1, size=3)+ 
geom_point(data = T, size=3)+ 
scale_y_continuous(limits = c(0, 40), expand = c(0, 0))+ 
scale_x_continuous(limits = c(0, 30), expand = c(0, 0))+ 
xlab("Inflorescence Length (cm)")+ 
ylab("Successful Weevils")+ 
theme_bw() + 
theme(panel.border = element_blank())+ 
theme(panel.grid.major = element_blank())+ 
theme(panel.grid.minor = element_blank())+ 
theme(axis.text=element_text(size=12))+ 
theme(axis.title=element_text(size=14,face="bold"))+ 
theme(axis.line.x=element_line())+ 
theme(axis.line.y=element_line())+ 
theme(plot.margin = unit(c(1,1,1,1), "cm"))+ 
stat_smooth(data = C, method = lm, se=FALSE, color="grey")+ 
stat_smooth(data = T, method = lm, se=FALSE, color="black") 
myplot 

謝謝!

回答

1

您必須關閉剪裁:

library(grid) 
library(ggplot2) 
df <- data.frame(x=1:1000, y=runif(1000)) 
p <- ggplot(df, aes(x,y)) + geom_point() + scale_y_continuous(limits = c(0,1), expand=c(0,0)) 
gt <- ggplot_gtable(ggplot_build(p)) 
gt$layout$clip[gt$layout$name=="panel"] <- "off" 
grid.draw(gt) 
相關問題