I can confirm your problem and also that Sandy's comment fixes it for me, using ggplot2 1.0 in R 3.1.2:
geom_vline(aes(xintercept = 3, linetype = lt))
However I still think this is a bug in (maybe just the documentation for) geom_vline
. I think xintercept
should be listed as a required aesthetic with a default value of 0. Notably, the code below "works" -- the lines have the correct hashing at the default x location of 0:
ggplot(foo, aes(x,y)) +
geom_point() +
geom_vline(aes(linetype=lt)) +
facet_wrap(~lt)
So the problem seems to be that when required aesthetics are supplied outside of aes()
, the arguments inside of aes()
are ignored. This is different than other functions. For example,
ggplot(foo) + geom_point(x=1, aes(y=y))
gives an error but
ggplot(foo) + geom_point(aes(x=1, y=y))
does not. As far as I'm concerned, ideal behavior would be for geom_vline()
to behave the same way as geom_point()
in this regard.