Changing ylim (axis limits) drops data falling outside range. How can this be prevented?
Posted
by Alex Holcombe
on Stack Overflow
See other posts from Stack Overflow
or by Alex Holcombe
Published on 2010-04-13T00:14:16Z
Indexed on
2010/04/13
0:23 UTC
Read the original article
Hit count: 263
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 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.
© Stack Overflow or respective owner