Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a vertical line to a time series plot

Tags:

r

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.

like image 727
orbital Avatar asked May 27 '13 12:05

orbital


People also ask

How do you plot a vertical line?

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!

How do you insert a vertical line in pandas plot?

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.

What function allows me to add vertical lines to a plot?

The abline() function can be used to add vertical, horizontal or regression lines to plot.


1 Answers

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"))
like image 193
James Avatar answered Oct 11 '22 18:10

James