0

I'm working on a set of scatter plots in R, and I want to add a vertical line to all of them. The x-axis is in Date type, and I think that's the problem for me. When I call

abline(v=movie_revenues$X, col="orange")

the line does not show up on the plot. The column "X" is the movie's premiere date, in this form: "11-Dec-2011". When I try to cast it as a date using as.Date(), it gives me an error saying that the text is in ambiguous form.

From this, I guess there are two points where I could have gone wrong.

  1. R doesn't recognize 11-Dec-2011 as a date, but tries to plot it anyway without throwing an error, resulting in a missing vertical line; or,
  2. the date is recognized correctly, but I've called abline incorrectly, or abline's plotted the line too thin/small for me to see (the y-axis on these plots are very large).

I'm new to R, so please let me know if there's anything silly I've missed.

Thanks!

majom
  • 7,863
  • 7
  • 55
  • 88
brian
  • 121
  • 2
  • 12
  • Try `dmy()`from the package `lubridate` instead of `as.Date()`. – majom Nov 24 '14 at 20:19
  • @majom So I think that should successfully convert into Dates (the error caused by as.Date() doesn't come up anymore), but the abline is still not showing. – brian Nov 24 '14 at 20:28
  • It would help if you could have a look at http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example and would set up an example this way. Thanks, – majom Nov 24 '14 at 20:30

1 Answers1

0

The issue was resolved when I used the lubridate package for BOTH my x-axis and my vertical line. For some reason, when I used as.Date() for the x-axis points but lubridate for the vertical line coordinate, the line would not appear.

brian
  • 121
  • 2
  • 12