[R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread Yuan, Rebecca
Hello, I do have two different time series A and B, they are different in length and starting point. A starts in Jan, 2012 and ends in Dec, 2012 and B starts in March, 2012 and ends in Nov, 2012. How can I plot those two series A and B in the same plot? I.E., from Jan. 2012 - Feb, 2012, it

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread PIKAL Petr
Hi -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Yuan, Rebecca Sent: Tuesday, January 22, 2013 4:07 PM To: R help Subject: [R] plot two time series with different length and different starting point in one figure.

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread Yuan, Rebecca
Hello Petr, As the time series have the same column names, I got the error message like: m1-merge(A, B, by.x = time, by.y = balance) Error in fix.by(by.x, x) : 'by' must specify uniquely valid column(s)

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread David Winsemius
On Jan 22, 2013, at 7:07 AM, Yuan, Rebecca wrote: Hello, I do have two different time series A and B, they are different in length and starting point. A starts in Jan, 2012 and ends in Dec, 2012 and B starts in March, 2012 and ends in Nov, 2012. How can I plot those two series A and B

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread Yuan, Rebecca
Hello Arun, This would help me to get the date type of data. A new question comes out that since the dates are not exactly the same on two date sets, there are some NA values in the merged data set, such as 2012-09-28 NA NA5400726 14861715970 2012-09-30 5035606 14832837436

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread Yuan, Rebecca
Hello David, If I use plot with the following code: plot(A, type = o, col = plot_colors[plotcolor], axes = FALSE, ann = FALSE) par(new=TRUE) plot(B, type = o, col = plot_colors[plotcolor+1], axes = FALSE, ann = FALSE) box() I

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread David Winsemius
On Jan 22, 2013, at 11:42 AM, Yuan, Rebecca wrote: Hello David, If I use plot with the following code: plot(A, type = o, col = plot_colors[plotcolor], axes = FALSE, ann = FALSE) par(new=TRUE) plot(B, type = o, col = plot_colors[plotcolor+1],

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread arun
Hi, dateA-seq.Date(as.Date(1jan2012,format=%d%b%Y),as.Date(31Dec2012,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=sample(1:300,366,replace=TRUE))  set.seed(25)  

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread arun
Hi, You could also try this: dateA-seq.Date(as.Date(1jan2012,format=%d%b%Y),as.Date(31Dec2012,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=sample(1:300,366,replace=TRUE))  set.seed(25)  

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread arun
Hi Rebecca, Assuming that 'raw_data' is data.frame with first column as raw_time: You could convert the raw_time to date format by  as.Date(28FEB2002,format=%d%B%Y) #[1] 2002-02-28 In your data, it should  be: raw_data$raw_time- as.Date(raw_time,format=%d%B%Y) Could you just dput() a few

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread arun
Hi Rebecca, In the previous email,   res-merge(Anew,Bnew) head(res) #   Anew Bnew #2012-01-01  181   NA #2012-01-02   59   NA #2012-01-03  290   NA #2012-01-04  196   NA #2012-01-05  111   NA #2012-01-06  297   NA   plot.zoo(res) # removes the NA values from Bnew.. (if NA was present in

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread arun
HI Rebecca, Try this: dateA-seq.Date(as.Date(28JAN2012,format=%d%B%Y),as.Date(28DEC2012,format=%d%B%Y),by=month) dateB-seq.Date(as.Date(30JAN2012,format=%d%B%Y),as.Date(30DEC2012,format=%d%B%Y),by=month) set.seed(15)  A-data.frame(dateA,value=cumsum(sample(1:50,12,replace=TRUE)))  set.seed(25)  

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread Yuan, Rebecca
Hello Arun, Thanks very much! In this way, it works! I convert both A and B to the same day of the month, and therefore there is no NA shown for different last business day and last calendar day of the month. You are very help! Cheers, Rebecca -Original Message- From: arun

Re: [R] plot two time series with different length and different starting point in one figure.

2013-01-22 Thread arun
Hi Rebecca, No problem. Just a doubt regarding the last calendar day and last business day. dateA-seq(as.Date(01FEB2012,format=%d%B%Y),length=15,by=1 month)-1   #gives the last calendar day/month dateB- seq.Date(as.Date(28MAR2012,format=%d%B%Y),as.Date(28DEC2012,format=%d%B%Y),by=month) #here I