How can we plot a lagged time series?

671    Asked by ManojSingh in Data Science , Asked on May 1, 2020
Answered by Manoj Singh

ggplot does not seem to have a lag.plot equivalent we can use tail to get a lagged version a vector:

tail(x,-1)



But within ggplot2 aesthetics must either be length one or having the same length, so we should append a value to the lagged one in order to plot it against the original vector. For example:

x= 1:10

qplot(x=x,y=c(tail(x,-1),0))



Another option is to use lag function from stats, but this assumes we are dealing with time series objects.





Your Answer

Interviews

Parent Categories