[R] plotting 2 time series data on the same graph

Rui Barradas ruipbarradas at sapo.pt
Sat May 4 11:48:47 CEST 2013


Hello,

I forgot a third possibility


plot(as.ts(cbind(x, y)), plot.type = "single", col = 1:2)


Rui Barradas

Em 04-05-2013 10:37, Rui Barradas escreveu:
> Hello,
>
> Where is the reproducible example? See
>
> http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
>
>
>
> Anyway, see if this does what you need.
>
> set.seed(1)
> x <- cumsum(rnorm(100))
> y <- cumsum(rnorm(100))
>
> ylm <- range(c(x, y))
> plot(as.ts(x), ylim = ylm)
> lines(y, col = "blue")
>
> # Or in one instruction
> matplot(cbind(x, y), type = "l")
>
>
> Hope this helps,
>
> Rui Barradas
>
>
> Em 04-05-2013 10:21, Preetam Pal escreveu:
>> Hi all,
>> I have 2 time series variables : X_t and Y_t  where  t=0,1,2,.......,100
>> I want a plot containing the line charts( time plotted on the x-axis) for
>> both these variables.
>>
>>
>>
>
> ______________________________________________
> 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