Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4102006
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:46:13+00:00 2026-05-20T20:46:13+00:00

Even though I found Hadley’s post in the google group on POSIXct and geom_vline

  • 0

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 lines

My date field has format “1993-07-01” and is of class Date.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:46:14+00:00Added an answer on May 20, 2026 at 8:46 pm

    Try as.numeric(mydata$datefield[120]):

    gg + geom_vline(xintercept=as.numeric(mydata$datefield[120]), linetype=4)
    

    A simple test example:

    library("ggplot2")
    
    tmp <- data.frame(x=rep(seq(as.Date(0, origin="1970-01-01"),
                                length=36, by="1 month"), 2),
                      y=rnorm(72),
                      category=gl(2,36))
    
    p <- ggplot(tmp, aes(x, y, colour=category)) +
         geom_line() +
         geom_vline(xintercept=as.numeric(tmp$x[c(13, 24)]),
                    linetype=4, colour="black")
    print(p)
    

    geom_vline example plot

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Even though I have a fermi card(gtx 560) I get this error on VS2010:
I can't seem to get heroku to db:push, even though I have installed taps.
Why can b list be found in some_list even though it's not in some_list?
What causes could there be, that gcc does not link to math.h even though
I keep getting a file not found error, even though it exists at /mnt/sdcard/folder/Samples.zip.
Even though it's not part of HTTP 1.1/RFC2616 webapps that wish to force a
One would expect that even though strings are immutable, value-equality and reference-equality would not
I've heard of GAE and even though it doesn't support PHP, people have gotten
I installed CKEditor, i found it causes large space between lines even though i'm
I have a C# solution and some referenced dll-s. Even though when compiling in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.