r - Lattice, xyplot, 2 time series on same graph (overlay) -


i want plot 2 time series on same graph, using xyplot.

here example of mean using ts.plot()

a1 = ts(rnorm(20), start=c(1980,1), freq=4) a2 = a1+3 ts.plot(a1,a2) 

i have tried

xyplot(merge(a1,a2))

which returns error, , have tried

xyplot(merge(as.xts(a1),as.xts(a2))) 

which plots them in different panels, not on same panel.

you can combine 2 time series objects using cbind (or, alternatively, ts.union). set superpose argument in xyplot true:

xyplot(cbind(a1, a2), superpose = true) 

time series plots superposed

short clarification: there s3 method xyplot handles ts (time series) objects. method (xyplot.ts) gets called when x argument xyplot time series object.


Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -