[R] different time series in one plot

Gabor Grothendieck ggrothendieck at gmail.com
Fri Oct 9 19:29:27 CEST 2009


plot.zoo and xyplot.zoo in the zoo package can both do that:

library(zoo)
z <- zoo(c(21, 34, 33, 41, 39, 38, 37, 28, 33, 40),
     as.Date(c("1992-01-10", "1992-01-17", "1992-01-24", "1992-01-31",
       "1992-02-07", "1992-02-14", "1992-02-21", "1992-02-28", "1992-03-06",
       "1992-03-13")))
# z and lag(z) have different spans and are irregular
zz <- merge(z, lag(z))

# same screem
plot(zz, screen = 1)
# different screens
plot(zz)

# similar but using zoo's xyplot lattice method
library(lattice)
xyplot(zz, screen = 1)
xyplot(zz)

Read the three vignettes that come with zoo and the help files.

On Fri, Oct 9, 2009 at 12:18 PM, Tomas Lanczos <lanczos at fns.uniba.sk> wrote:
> Hello,
>
> I need to put 2 or more different time series to one plot for comparison
> each other. The problem is that the time series are irregular, moreover
> the time lenghts and periods are not the same. Is there a way to manage
> it in R?
>
> Many thanks for any hint and advice in advance
>
> Tomas
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list