[R] Labeling Dates of different length on two in axis plot

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Sun Aug 25 10:33:17 CEST 2019


Hi Ogbos,
Hope things are going well for you. Perhaps this is what you want:

date_x1<-seq(as.Date("1953-01-02"),as.Date("2006-11-15"),length.out=8)
value_x1<-sample(1000:5000,8)
date_x2<-seq(as.Date("1957-07-26"),as.Date("1994-07-17"),length.out=6)
value_x2<-sample(0:1000,6)
plot(date_x1,value_x1,type="b",col="red",xlab="Year",ylab="x1",
 ylim=c(0,max(value_x1)))
points(date_x2,value_x2,type="b",col="blue")

Jim

On Sun, Aug 25, 2019 at 2:49 PM Ogbos Okike <giftedlife2014 using gmail.com> wrote:
>
> Dear Contributors,
> I have two dataset of different lengths, each containing year, month,
> day and counts.
> After converting the date using as.Date function, I plotted the two
> dateset on one graph. That was fine.
>
> I am, however, having problems with the axis 1 where I am trying to
> put the dates.
> Since the two dates are not exactly the same, I stored the first date
> as x1 and the second x2. x1 runs from 1953-01-02 to 2006-11-15 while
> the range of x2 is between 1957-07-26 and 1994-07-17.
> I tired a number of approaches but the one that seems to come close to
> what I am looking for is: axis.Date(1, at=seq(min(x1), max(x1), by="50
> mon"), format="%Y").
>
> Unfortunately, it only labeled the axis up to 1994 even when I tried
> to replace x1 with x2 in the code. Since one of the dates is up to
> 2006, I I wish to display the minimum (1953) and maximum  (2006) dates
> and some possible intermediary dates.
> I am always indebted to you.
>
> Best wishes
> Ogbos
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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