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

Rui Barradas ruipbarradas at sapo.pt
Sat May 4 11:37:28 CEST 2013


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.
>
>
>



More information about the R-help mailing list