df <- data.frame(age=c(10,10,20,20,25,25,25),veg=c(0,1,0,1,1,0,1))
g=ggplot(data=df,aes(x=age,y=veg))
g=g+stat_summary(fun.y=mean,geom="point")
Points reflect mean of veg at each age, which is what I expected and want to preserve after changing axis limits with the command below.
g=g+ylim(0.2,1)
Changing axis limits with the above command unfortunately causes veg==0 subset to be dropped from the data, yielding
"Warning message: Removed 4 rows containing missing values (stat_summary)"
This is bad because now the data plot (stat_summary mean) omits the veg==0开发者_JAVA技巧 points. How can this be prevented? I simply want to avoid showing the empty part of the plot- the ordinate from 0 to .2, but not drop the associated data from the stat_summary calculation.
you can do that by specifying the coord system:
df <- data.frame(age=c(10,10,20,20,25,25,25),veg=c(0,1,0,1,1,0,1))
g=ggplot(data=df,aes(x=age,y=veg))
g=g+stat_summary(fun.y=mean,geom="point")
g+coord_cartesian(ylim=c(0.2,1)) #do not use +ylim() here
精彩评论