[R] superpose 2 time series with different time intervals

Gabor Grothendieck ggrothendieck at gmail.com
Sat Aug 1 12:12:33 CEST 2009


Try this:

# two simulated series
set.seed(123)
ts.sim <- arima.sim(list(order = c(1,1,0), ar = 0.7), n = 70)
ts.sim <- ts(c(ts.sim), start = 1940)
ts.sim2 <- arima.sim(list(order = c(1,1,0), ar = 0.7), n = 12*70)
ts.sim2 <- ts(c(ts.sim2), start = 1940, freq = 12)

# plot
plot(ts.sim2, type = "l", col = grey(0.5))
lines(ts.sim)
axis(1, time(ts.sim), lab = FALSE)


On Fri, Jul 31, 2009 at 3:15 PM, Gary Lewis<gary.m.lewis at gmail.com> wrote:
> I  could use some advice.
>
> I've got 2 time series. Both cover approximately the same period of
> time (ie, 1940 to 2009). But one series has annual data and the other
> has monthly data. One refers to university enrollment; the other to
> unemployment rates. Both are currently in the same data frame.
>
> I'd like to use the monthly times series as a light grayscale
> background for a plot of the annual time series, showing both series
> as type "l" (line). Naturally with all the NA's in the annual series,
> that plot disappears because points are not connected across missing
> values.
>
> I suppose I could make both series annual, but a lot of interesting
> detail would get lost this way. Or I guess I could interpolate values
> in the annual series with monthly approximations, but this means 11
> out of every 12 values is an approximation. Or I suppose I could plot
> each series separately and then print them with position information,
> which I'm reluctant to do because panel.superpose so nicely handles
> the alignment of the 2 panels.
>
> What I'd really like to do is plot each independently but still
> superposed. Effectively this seems to mean monthly data intervals but
> line connections across the NA's in the series with annual intervals.
>
> Any suggestions would be appreciated. Thanks.
>
> Gary Lewis
>
> ______________________________________________
> 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