Add a vertical line with ggplot when x-axis is a factor

ggplot2, r

Solution

I don't know (don't remember) if your original used to work with old version of ggplot but you can use an another approach like this one :

ggplot(df, aes(x=x, y=y)) + geom_bar() + geom_vline(xintercept=which(df$x == 'm'))

Hope this help !!!

Problem

The following code use to work pre-version .9 of ggplot2. Is this not possible anymore? ``` df = data.frame(x = letters[1:26], y=abs(rnorm(26))) ggplot(df, aes(x=x, y=y)) + geom_bar() + geom_vline(xintercept='m') ``` I get the following error: Error in get(as.character(FUN), mode = "function", envir = envir) : object 'm' of mode 'function' was not found

Original source