I am relatively new to ggplot2, having used base graphics in R for many years. One thing I always liked about base graphics is the extra padding in the axes, so that the two axes do not tend to touch in the origin. Here is a simple example in base graphics:
png(file="base.png")
plot(x,y, bty="n")
dev.off()
which makes:
whereaas, when I do something similar in ggplot2
require(ggplot2)
x <- y <- 1:10
png(file="qplot.png")
qplot(x, y) + theme_classic()
dev.off()
I get:
How can I adjust the extent to which axes are drawn? e.g. for the y axis, I'd prefer it to stop at 10.0, rather than continuing to about 10.5?
Update: thanks for the comments. I now have what I'd like; here's a snippet that draws the axes out only as far as the min/max tick on each axis.
o = qplot(x, y) + theme_classic() +
theme(axis.line=element_blank())
oo = ggplot_build(o)
xrange = range(oo$panel$ranges[[1]]$x.major_source)
yrange = range(oo$panel$ranges[[1]]$y.major_source)
o = o + geom_segment(aes(x=xrange[1], xend=xrange[2], y=-Inf, yend=-Inf)) +
geom_segment(aes(y=yrange[1], yend=yrange[2], x=-Inf, xend=-Inf))
plot(o)