[R] Plotting two time series with different frequencies

Gabor Grothendieck ggrothendieck at gmail.com
Fri Feb 25 05:16:24 CET 2011


On Thu, Feb 24, 2011 at 3:13 PM, Gabriel Bergin <gabriel at bergin.se> wrote:
> Hi,
>
> I have two time series; one of annual data and one of monthly data. How do I
> plot these on the same plot? I checked out ts.plot(), but it only allows for
> different starting times, not different frequencies.
>

Try this assuming ser1 and ser2 are your two ts series:

plot(ser1)
lines(ser2, col = 2)

Another way is:

library(zoo)
z <- na.approx(cbind(as.zoo(ser1), as.zoo(ser2)))
time(z) <- as.yearmon(time(z))
plot(z, screen = 1, col = 1:2)

Omit screen = 1 to get separate panels.


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list