Ogbos Okike
2019-Aug-25 04:48 UTC
[R] Labeling Dates of different length on two in axis plot
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
Jim Lemon
2019-Aug-25 08:33 UTC
[R] Labeling Dates of different length on two in axis plot
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 at 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 at 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.
Bert Gunter
2019-Aug-25 14:57 UTC
[R] Labeling Dates of different length on two in axis plot
I think you will need to show us your code to get useful help (see the posting guide). A small subset of your data and a reprex may also be needed. R has several different graphics systems, and the answer depends on which you are using. In base graphics, the axis() function (see its Help page) may be what you need, but that's just a guess. Others may be able to be more specific. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sat, Aug 24, 2019 at 9:49 PM Ogbos Okike <giftedlife2014 at 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 at 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. >[[alternative HTML version deleted]]
Ogbos Okike
2019-Aug-25 15:52 UTC
[R] Labeling Dates of different length on two in axis plot
Dear Jim and Bert, Thank your for looking into this for me. I will try to reproduce a part of my data and the plot I have. Data 1: 53 01 02 -1.28792560381641 53 01 06 -1.1854773963453 53 01 08 -1.55920165458006 53 01 15 -1.29196482429683 53 01 20 -1.06082194329819 53 01 22 -1.15430411152234 53 01 24 -1.14775155345262 53 01 26 -1.19116423468105 53 01 28 -0.924542121164923 53 01 31 -0.869543637175866 53 02 03 -0.764466677206437 53 02 05 -0.707705051599105 53 02 07 -0.750908466521414 53 02 16 -1.6848903649715 53 02 20 -0.760876361940755 53 02 22 -0.803816591115474 53 02 26 -0.818160891300922 53 02 28 -0.831013020625678 53 03 04 -1.06661138281899 till the year 2006. The length is 1575 Data B: 57 07 26 -3.62351759422703 57 07 29 -4.51297753038541 57 08 02 -3.29214621128099 57 08 05 -6.44144118698436 57 08 16 -3.09828319252649 57 08 22 -1.58619965424759 57 08 28 -4.3638763217976 57 08 30 -9.93305062749234 57 09 03 -9.29132498735799 57 09 05 -8.50042591710719 57 09 13 -5.58659819576993 57 09 19 -2.4834966827445 57 09 23 -5.69132573226493 57 09 26 -3.6296458026372 to the year 1994. The length is 1203. The plot is attached. How to label the x-axis is the problem. I will send the code in another email so that the moderator will let it go. Thank again Best Ogbos On Sun, Aug 25, 2019 at 3:58 PM Bert Gunter <bgunter.4567 at gmail.com> wrote:> > I think you will need to show us your code to get useful help (see the posting guide). A small subset of your data and a reprex may also be needed. R has several different graphics systems, and the answer depends on which you are using. In base graphics, the axis() function (see its Help page) may be what you need, but that's just a guess. Others may be able to be more specific. > > Cheers, > Bert > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Sat, Aug 24, 2019 at 9:49 PM Ogbos Okike <giftedlife2014 at 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 at 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.-------------- next part -------------- A non-text attachment was scrubbed... Name: Ogbos.pdf Type: application/pdf Size: 39312 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20190825/d6c0f233/attachment.pdf>