Is is possible to use abline() and add a vertical line to a plot where the x axis contains dates? I've tried many possible date formatting but can't get it to work.
To graph a vertical line that goes through a given point, first plot that point. Then draw a straight line up and down that goes through the point, and you're done!
Using axvline(), add a vertical line across the axes, where color is green, linestyle="dashed". Using axvline(), add a vertical line across the axes, where color is red, linestyle="dashed". Using plt. show(), show the plot.
The abline() function can be used to add vertical, horizontal or regression lines to plot.
Yes, the easiest way is to provide a Date
object to abline
:
x <- as.Date("2013-05-27")+0:99
y <- cumsum(rnorm(100))
plot(x,y)
abline(v=as.Date("2013-08-01"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With