There always seems to be some small but noticeable offset between where tick marks end and where the panel starts.
This is more evident when axis limits are specified so that the axis ends on a tick (see above). e.g., On the y-axis, the highest tick is too high and the lowest tick is too low.
Code to reproduce:
library(ggplot2)
p <-
ggplot(mtcars,aes(mpg, wt)) +
geom_point() +
scale_y_continuous(limits=c(1,5), expand=c(0,0))
p <- p + theme_few()
p <- p + theme(axis.ticks=element_line(size=0.5),axis.ticks.length = unit(0.5, "cm")) # enlarged for clarity, although this happens regardless
How can I fix this?
Edit:
In using the accepted answer on my own data, I noticed this also changes how points at the axis extrema are clipped. Is there any way to correctly align ticks and the panel, but not change this behavior? I don't want to remove the points, just still hide the portions outside the panel.