R

Asked • 10/04/19

How to get a vertical geom_vline to an x-axis of class date?

Even though I found Hadley's post in the google group on `POSIXct` and `geom_vline`, I could not get it done. I have a time series from and would like to draw a vertical line for years 1998, 2005 and 2010 for example. I tried with `ggplot` and `qplot` syntax, but still I either see no vertical line at all or the vertical line is drawn at the very first vertical grid and the whole series is shifted somewhat strangely to the right. gg <- ggplot(data=mydata,aes(y=somevalues,x=datefield,color=category)) + layer(geom="line") gg + geom_vline(xintercept=mydata$datefield[120],linetype=4) # returns just the time series plot I had before, # interestingly the legend contains dotted vertical linesMy date field has format "1993-07-01" and is of class `Date`.

1 Expert Answer

By:

Justin R. answered • 11/22/20

Tutor
5.0 (170)

Ph.D. in Geophysics. Teaching at the university level since 1990.

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.