My data range always seems to be greater than the top label in the y-axis. Is there a way I can automatically include it without manually setting limits?
e.g. in
So I don't think expand is actually the way to go about this, rather expand_limits.
This is clearly not the most beautiful code, but this is basically the functionality I'm looking for where the labels on the y-axis encompass the data completely.
dat<-data.frame(x=1:10, y=c(11:17,5:3))
ggplot(dat, aes(x,y)) +
geom_point() +
expand_limits(y=c(min(pretty(c(dat$y, min(dat$y) * (0.95)))), max(pretty(c(dat$y, max(dat$y) * (1.05))))))

I've assumed expand default as 0.05 and that pretty is used with defaults. Is there a better way to do this?