We might wish to indicate specific points of importance or measurements in a time series, where there is a significant event or change in the data. In this recipe, we will learn how to add vertical markers using the abline()
function.
We will only use the basic R functions for this recipe. Make sure that you are at the R prompt and load the openair.csv
dataset:
air<-read.csv("openair.csv")
Let's take our air pollution time series example again and draw a red vertical line on Christmas day, 25/12/2003
:
plot(air$nox~as.Date(air$date,"%d/%m/%Y %H:%M"),type="l", xlab="Time", ylab="Concentration (ppb)", main="Time trend of Oxides of Nitrogen") abline(v=as.Date("25/12/2003","%d/%m/%Y"))