I have some data which is inherently positive, and would like to ensure that all graphs in a facet-grid start with y=0, but scale appropriately on the high end.
For example, suppose I'm comparing the growth of hamburger and hot dog sales from year to year:
fr <-
data.frame(
year=rep(1:10,2), # 2 runs of 10
quant=(c(1:10,1:10*3)+rnorm(20,0,3))^2, # some variation in dependent var
type=rep(c('hamburgers','hot dogs'),each=10)) # first 10 and second 10 are separate series
and plot it with:
ggplot(fr,aes(x=year,y=quant)) +
geom_point() +
geom_smooth() +
facet_grid(type~.,scales="free")
This is fine, except that the geom_smooth overflows into (meaningless) negative values.
So I'd like to do something like
+ coord_cartesian(ylim=c(0,NA)) # causes internal error
to ensure that the lower y limit is always at 0 to make the graphs comparable. I do, however, want to let the upper y limit be free.
How do I do this in ggplot?
-s