I added a zero initial entry to the data set. Greg gcdf<-read.table(text="2013-11-29 00.000 2013-12-29 19.175 2014-01-20 10.072 2014-02-12 10.241 2014-03-02 05.916> On Dec 16, 2020, at 12:32 PM, Gregory Coats via R-help <r-help at r-project.org> wrote: > > Jim, Thank you! > The data set begins > gcdf<-read.table(text="2013-12-29 19.175 > 2014-01-20 10.072 > 2014-02-12 10.241 > I note that data begins in 2013. But the plot command does not show this first entry in 2013, and instead shows the second data pair as the first data pair. As a consequence, plot does not show the first data pair for 2013, and begins in 2014. > Greg > >> On Dec 16, 2020, at 1:08 AM, Jim Lemon <drjimlemon at gmail.com> wrote: >> >> Hi Greg, >> I think this does what you want: >> >> gcdf$date<-as.Date(gcdf$date,"%Y-%m-%d") >> grid_dates<-as.Date(paste(2014:2020,1,1,sep="-"),"%Y-%m-%d") >> plot(gcdf$date, gcdf$gallons, main="2014 Toyota 4Runner", xlab="Date", >> ylab="Gallons",type="l",col="blue",yaxt="n") >> abline(h=seq(4,20,by=2),lty=4) >> abline(v=grid_dates,lty=4) >> axis(side=2,at=seq(4,20,by=2)) >> >> Jim >> >> On Wed, Dec 16, 2020 at 2:16 PM Gregory Coats <gregcoats at me.com> wrote: >>> >>> Jim, Thanks for your help with R. >>> Feeding into R the file R_plot_18.r yields for me, on my Mac, R_plot_18.pdf. Success. >>> I used abline to draw a horizontal background grid, and then used axis label to identify the values represented by the horizontal dashed background lines. >>> abline (h=c(2,4,6,8,10,12,14,16,18,20,22,24), lty=4, lwd=1.0, col="grey60") >>> Similarly, I would like to draw a dashed vertical background grid. But it is unclear to me how to direct R to draw a vertical dashed background grid because I am again baffled how to specify to R a date value such as 2018-10-20 @18:00. I welcome your guidance. >>> Greg >>> >>> On Dec 13, 2020, at 10:58 PM, Jim Lemon <drjimlemon at gmail.com> wrote: >>> >>> Hi Gregory, >>> >>> On Mon, Dec 14, 2020 at 12:34 PM Gregory Coats <gregcoats at me.com> wrote: >>> >>> ... >>> Is there a convenient way to tell R to interpret ?2020-12-13? as a date? >>> >>> Notice the as.Date command in the code I sent to you. this converts a >>> string to a date with a resolution of one day. If you want a higher >>> time resolution, use strptime or one of the other POSIX date >>> conversion functions. >>> >>> Jim
You didn't show the entire call to read.table. If it included the argument header=TRUE then it would make the first entry in each column the name of the column. Use header=FALSE (or omit the header argument) if you don't want the first entry to be considered the column name. -Bill On Wed, Dec 16, 2020 at 10:25 AM Gregory Coats via R-help < r-help at r-project.org> wrote:> I added a zero initial entry to the data set. Greg > gcdf<-read.table(text="2013-11-29 00.000 > 2013-12-29 19.175 > 2014-01-20 10.072 > 2014-02-12 10.241 > 2014-03-02 05.916 > > > On Dec 16, 2020, at 12:32 PM, Gregory Coats via R-help < > r-help at r-project.org> wrote: > > > > Jim, Thank you! > > The data set begins > > gcdf<-read.table(text="2013-12-29 19.175 > > 2014-01-20 10.072 > > 2014-02-12 10.241 > > I note that data begins in 2013. But the plot command does not show this > first entry in 2013, and instead shows the second data pair as the first > data pair. As a consequence, plot does not show the first data pair for > 2013, and begins in 2014. > > Greg > > > >> On Dec 16, 2020, at 1:08 AM, Jim Lemon <drjimlemon at gmail.com> wrote: > >> > >> Hi Greg, > >> I think this does what you want: > >> > >> gcdf$date<-as.Date(gcdf$date,"%Y-%m-%d") > >> grid_dates<-as.Date(paste(2014:2020,1,1,sep="-"),"%Y-%m-%d") > >> plot(gcdf$date, gcdf$gallons, main="2014 Toyota 4Runner", xlab="Date", > >> ylab="Gallons",type="l",col="blue",yaxt="n") > >> abline(h=seq(4,20,by=2),lty=4) > >> abline(v=grid_dates,lty=4) > >> axis(side=2,at=seq(4,20,by=2)) > >> > >> Jim > >> > >> On Wed, Dec 16, 2020 at 2:16 PM Gregory Coats <gregcoats at me.com> wrote: > >>> > >>> Jim, Thanks for your help with R. > >>> Feeding into R the file R_plot_18.r yields for me, on my Mac, > R_plot_18.pdf. Success. > >>> I used abline to draw a horizontal background grid, and then used axis > label to identify the values represented by the horizontal dashed > background lines. > >>> abline (h=c(2,4,6,8,10,12,14,16,18,20,22,24), lty=4, lwd=1.0, > col="grey60") > >>> Similarly, I would like to draw a dashed vertical background grid. But > it is unclear to me how to direct R to draw a vertical dashed background > grid because I am again baffled how to specify to R a date value such as > 2018-10-20 @18:00. I welcome your guidance. > >>> Greg > >>> > >>> On Dec 13, 2020, at 10:58 PM, Jim Lemon <drjimlemon at gmail.com> wrote: > >>> > >>> Hi Gregory, > >>> > >>> On Mon, Dec 14, 2020 at 12:34 PM Gregory Coats <gregcoats at me.com> > wrote: > >>> > >>> ... > >>> Is there a convenient way to tell R to interpret ?2020-12-13? as a > date? > >>> > >>> Notice the as.Date command in the code I sent to you. this converts a > >>> string to a date with a resolution of one day. If you want a higher > >>> time resolution, use strptime or one of the other POSIX date > >>> conversion functions. > >>> > >>> Jim > > ______________________________________________ > 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]]
I would like to be able to draw and label a vertical line, representing the date
of some arbitrary event. The date of the first non-zero entry is 2013-11-29. How
would I draw and label a red vertical line at 2019-04-06? Greg
gcdf<-read.table(text="2013-11-29 00.000
2013-12-29 19.175
2014-01-20 10.072
2014-02-12 10.241
2014-03-02 05.916
2014-03-15 05.942
2014-03-23 03.639
2014-04-06 08.283
2014-04-20 07.323
2014-05-11 09.807
2014-05-30 10.398
2014-06-15 13.949
2014-07-06 13.840
2014-07-18 07.906
2014-07-21 13.609
2014-08-03 17.316
2014-08-10 09.585
2014-08-24 16.022
2014-09-07 15.403
2014-09-21 14.880
2014-10-08 18.950
2014-10-24 18.185
2014-11-03 10.178
2014-11-09 07.438
2014-11-23 16.053
2014-12-07 12.896
2014-12-21 18.306
2015-01-05 16.580
2015-01-18 14.603
2015-01-25 08.192
2015-02-08 15.690
2015-02-16 08.677
2015-03-08 15.493
2015-03-22 16.065
2015-04-05 15.990
2015-04-19 19.076
2015-04-26 11.310
2015-05-03 09.243
2015-05-10 13.366
2015-05-17 11.191
2015-05-25 12.329
2015-05-31 08.324
2015-06-07 12.985
2015-06-15 12.605
2015-06-21 09.759
2015-06-28 14.906
2015-07-05 09.106
2015-07-12 11.306
2015-07-19 10.052
2015-07-26 08.845
2015-08-02 11.634
2015-08-09 07.718
2015-08-16 06.057
2015-08-23 08.341
2015-08-30 06.702
2015-09-07 05.972
2015-09-13 08.249
2015-09-20 05.758
2015-10-05 13.772
2015-10-19 14.144
2015-11-03 14.305
2015-11-13 09.932
2015-11-20 17.418
2015-12-06 13.529
2015-12-20 15.440
2016-01-03 10.573
2016-01-19 09.592
2016-02-25 12.664
2016-04-03 18.993
2016-05-01 16.869
2016-06-07 15.012
2016-06-23 07.549
2016-06-27 13.756
2016-08-07 18.581
2016-09-01 11.334
2016-09-30 11.327
2016-11-06 18.018
2016-11-27 14.597
2016-12-04 15.347
2016-12-23 09.243
2017-01-05 16.035
2017-02-07 13.219
2017-02-19 16.196
2017-03-12 07.436
2017-05-08 19.747
2017-06-29 19.503
2017-08-15 19.676
2017-09-08 15.558
2017-10-17 16.705
2017-12-06 14.876
2018-01-12 13.748
2018-03-15 19.139
2018-04-13 19.056
2018-05-20 17.756
2018-06-02 15.631
2018-06-17 14.049
2018-07-05 18.870
2018-07-22 16.654
2018-08-06 17.171
2018-08-26 20.139
2018-09-09 18.442
2018-09-26 18.646
2018-10-14 17.144
2018-11-02 19.508
2018-11-20 12.454
2018-12-04 09.355
2018-12-14 09.152
2019-01-11 10.998
2019-02-02 07.739
2019-02-19 09.891
2019-03-22 18.716
2019-04-30 18.880
2019-06-03 19.247
2019-07-07 18.289
2019-08-30 19.021
2019-09-29 15.892
2019-10-26 18.180
2019-11-17 17.693
2019-12-08 16.528
2020-01-05 15.973
2020-02-15 18.832
2020-03-10 17.392
2020-05-04 14.774
2020-06-21 19.248
2020-08-01 14.913
2020-08-27 15.226
2020-09-28 14.338
2020-11-09 18.777
2020-12-11 19.652",
header=TRUE,stringsAsFactors=FALSE,
col.names=c("date","gallons"))
gcdf$date<-as.Date(gcdf$date,"%Y-%m-%d")
grid_dates<-as.Date(paste(2013:2021,1,1,sep="-"),"%Y-%m-%d")
plot (gcdf$date, gcdf$gallons, ylab="Refueling Gallons",
xlab="",type="l", col="blue", yaxt="n")
mtext (side=3, line="+0", "2014 Toyota 4Runner")
abline (h=seq(4,20,by=2), lty=3)
abline (v=grid_dates, lty=4)
axis (side=2, at=seq(4,20,by=2))
[[alternative HTML version deleted]]