Hi, One more possibility: dateA<-seq.Date(as.Date("1jan2012",format="%d%b%Y"),as.Date("14Feb2013",format="%d%b%Y"),by="day") dateB<-seq.Date(as.Date("1Mar2012",format="%d%b%Y"),as.Date("30Nov2012",format="%d%b%Y"),by="day") set.seed(15) A<-data.frame(dateA,value=cumsum(rnorm(411))) set.seed(25) B<-data.frame(dateB,value=cumsum(rnorm(275))) library(xts) Anew<-as.xts(A[,-1],order.by=A[,1]) Bnew<-as.xts(B[,-1],order.by=B[,1]) res<-merge(Anew,Bnew) res1<-res[complete.cases(res),] #install.packages("xtsExtra", repos='http://r-forge.r-project.org') library(xtsExtra) plot(res,screens=1,main="Time Series") plot(res1,col=c(1,3)) A.K.
----- Original Message ----- From: Rui Barradas <ruipbarra...@sapo.pt> To: Preetam Pal <lordpree...@gmail.com> Cc: r-help@r-project.org Sent: Saturday, May 4, 2013 5:48 AM Subject: Re: [R] plotting 2 time series data on the same graph 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@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. ______________________________________________ R-help@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.
TimeSeries.pdf
Description: Adobe PDF document
______________________________________________ R-help@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.