Adding a vline in ggplot2 using time

后端 未结 1 1253
独厮守ぢ
独厮守ぢ 2021-01-01 06:56

I am having some problems adding a vertical line to a gplot2 graph.

My example dataframe is listed below.

set.seed(1234)
df <- data.frame(Date=seq         


        
相关标签:
1条回答
  • 2021-01-01 07:28

    You have to replace as.Date() with as.POSIXct() because you also need time not just date (function as.Date() represents only date part).

    g + geom_vline(xintercept=as.numeric(as.POSIXct("2013-02-21 14:00:00")))
    

    You can see the difference by looking on those two cases:

     as.Date("2013-02-21 14:00:00")
    [1] "2013-02-21"
    
     as.POSIXct("2013-02-21 14:00:00")
    [1] "2013-02-21 14:00:00 EET"
    
    0 讨论(0)
提交回复
热议问题