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

后端 未结 2 1995
無奈伤痛
無奈伤痛 2021-02-20 17:13

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,          


        
2条回答
  •  醉梦人生
    2021-02-20 18:07

    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 !!!

提交回复
热议问题