0

Does anyone know how to use geom_vline() in ggplot with time series data?

I know if the x axis has dates I can use as.numeric(as.Date()) to plot the vertical line as shown below, but how can I plot the vertical line if my x axis is UTC time? e.g. a vertical line at 21:30?

geom_vline(xintercept = as.numeric(as.Date("2019-10-03")))

# would plot a vertical line at October 3rd 2019

javery1289
  • 67
  • 7
  • Date data distinguishes between days but you want a date-time format, most typically POSIXct. One simple way to create is `lubridate::ymd_hm(201910032130)` or `lubridate::ymd_hm("2019-10-03 21:30")`. – Jon Spring Oct 05 '19 at 00:36
  • It would be easier to help with a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). That includes a sample of data, all necessary code, and a clear explanation of what you're trying to do and what hasn't worked. – camille Oct 05 '19 at 00:43

0 Answers0