[R] How to specify year-month-day for a plot

Gregory Coats gregco@t@ @end|ng |rom me@com
Wed Dec 16 20:09:18 CET 2020


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]]



More information about the R-help mailing list