I am using R 3.5.0 for Mac OS X. Issuing these two commands yields the expected plot. y_duration <- c (301.59050, 387.35700, 365.64366, 317.26150, 321.71883, 342.44950, 318.95350, 322.33233, 330.60333, 428.99516, 297.82066) plot (y_duration, type="l?) Adding Year-Month-Day values for the x axis, and then calling plot (x,y), yields a bizarre plot. Apparently, R does not understand my Year-Month-Day values. x_yyyymmdd <- c (2018-04-25, 2018-04-26, 2018-04-27, 2018-04-28, 2018-04-29, 2018-04-30, 2018-05-01, 2018-05-02, 2018-05-03, 2018-05-04, 2018-05-05) plot (x_yyyymmdd, y_duration, type="l") I would be enormously appreciative of your guidance. Greg Coats Virginia, USA [[alternative HTML version deleted]]
Hi Greg, What you are getting there is a factor, interpreted as a 1:n sequence based on the sort order of your "dates". Here's a way to get dates on your x-axis in the format you want: x_yyyymmdd<-as.Date(c("2018-04-25","2018-04-26","2018-04-27", "2018-04-28","2018-04-29","2018-04-30","2018-05-01","2018-05-02", "2018-05-03","2018-05-04","2018-05-05"),format="%Y-%m-%d") plot(x_yyyymmdd, y_duration, type="l",xaxt="n") library(plotrix) staxlab(1,at=x_yyyymmdd,labels=format(x_yyyymmdd,"%Y-%m-%d")) Jim On Sun, May 6, 2018 at 4:14 AM, Gregory Coats <gregcoats at me.com> wrote:> I am using R 3.5.0 for Mac OS X. > Issuing these two commands yields the expected plot. > y_duration <- c (301.59050, 387.35700, 365.64366, 317.26150, 321.71883, 342.44950, 318.95350, 322.33233, 330.60333, 428.99516, 297.82066) > plot (y_duration, type="l?) > > Adding Year-Month-Day values for the x axis, and then calling plot (x,y), yields a bizarre plot. Apparently, R does not understand my Year-Month-Day values. > x_yyyymmdd <- c (2018-04-25, 2018-04-26, 2018-04-27, 2018-04-28, 2018-04-29, 2018-04-30, 2018-05-01, 2018-05-02, 2018-05-03, 2018-05-04, 2018-05-05) > plot (x_yyyymmdd, y_duration, type="l") > > I would be enormously appreciative of your guidance. > Greg Coats > Virginia, USA > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
"Apparently, R does not understand my Year-Month-Day " I think, rather, you need to learn how R handles dates and times. See here to begin, perhaps: ?DateTimeClasses There are many R resources for dealing with data over time, many of which are listed here, and others might be found by online searching. https://cran.r-project.org/web/views/TimeSeries.html There are also many tutorials on dealing with time data in R. Even a cursory web search should find many. ... and of course someone may respond directly to your query here (but not me, as I'm not that knowledgeable). 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, May 5, 2018 at 11:14 AM, Gregory Coats <gregcoats at me.com> wrote:> I am using R 3.5.0 for Mac OS X. > Issuing these two commands yields the expected plot. > y_duration <- c (301.59050, 387.35700, 365.64366, 317.26150, > 321.71883, 342.44950, 318.95350, 322.33233, 330.60333, 428.99516, > 297.82066) > plot (y_duration, type="l?) > > Adding Year-Month-Day values for the x axis, and then calling plot (x,y), > yields a bizarre plot. Apparently, R does not understand my Year-Month-Day > values. > x_yyyymmdd <- c (2018-04-25, 2018-04-26, 2018-04-27, 2018-04-28, > 2018-04-29, 2018-04-30, 2018-05-01, 2018-05-02, 2018-05-03, 2018-05-04, > 2018-05-05) > plot (x_yyyymmdd, y_duration, type="l") > > I would be enormously appreciative of your guidance. > Greg Coats > Virginia, USA > [[alternative HTML version deleted]] > > ______________________________________________ > 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]]
Jim, Thanks for responding! I am using the official R 3.5.0 for Mac OS X. This apparently does not include library (plotrix) library(plotrix) Error in library(plotrix) : there is no package called ?plotrix? Greg> On May 5, 2018, at 6:50 PM, Jim Lemon <drjimlemon at gmail.com> wrote: > > Hi Greg, > What you are getting there is a factor, interpreted as a 1:n sequence > based on the sort order of your "dates". Here's a way to get dates on > your x-axis in the format you want: > > x_yyyymmdd<-as.Date(c("2018-04-25","2018-04-26","2018-04-27", > "2018-04-28","2018-04-29","2018-04-30","2018-05-01","2018-05-02", > "2018-05-03","2018-05-04","2018-05-05"),format="%Y-%m-%d") > plot(x_yyyymmdd, y_duration, type="l",xaxt="n") > library(plotrix) > staxlab(1,at=x_yyyymmdd,labels=format(x_yyyymmdd,"%Y-%m-%d")) > > Jim[[alternative HTML version deleted]]
Jim, That you very much! How do I instruct staxlab to label once every n days, rather than labeling every day? Greg> On May 5, 2018, at 6:50 PM, Jim Lemon <drjimlemon at gmail.com> wrote: > > staxlab(1,at=x_yyyymmdd,labels=format(x_yyyymmdd,"%Y-%m-%d"))[[alternative HTML version deleted]]