After a bit of searching I am still not happy!
Is there a simple way to make a graph with a y-axis that starts at the origin and clearly shows all your data?
<I found this issue frustrating, and then read the R help file for expansion()
. There is a good ggplot option for this that is facet-friendly, dynamic, and concise.
Quoting from the help file:
mult
vector of multiplicative range expansion factors. If length 1, both the lower and upper limits of the scale are expanded outwards by mult. If length 2, the lower limit is expanded by mult[1] and the upper limit by mult[2].
Note that add
is also an option with similar structure. I would solve this issue like so:
ggplot(my.data, aes(x.var, y.var))+
geom_point()+
scale_y_continuous(limits = c(0, NA),
expand = expansion(mult = c(0, 0.1)))
A big reason to prefer this appraoch is if you have geoms with different aesthetics (e.g. points and error bars) and facets with free scales... you can still take advantage of ggplot's clever default y-axis behavior, but force x to intersect y at 0 in every panel, and still see the uppermost data points.
Why not just:
ggplot(my.data, aes(x.var, y.var))+
geom_point()+
scale_y_continuous(expand = c(0,0))+
expand_limits(y = c(0,1.05 * max(my.data$y.var)))