Skip to content
Prev 387454 / 398502 Next

How to plot dates

Hi Greg,
This example may give you a start:

myDat<-read.table(text=
  "2021-03-11 10:00:00
  2021-03-11 14:17:00
  2021-03-12 05:16:46
  2021-03-12 09:17:02
  2021-03-12 13:31:43
  2021-03-12 22:00:32
  2021-03-13 09:21:43",
  sep=",",
  stringsAsFactors=FALSE)
myDat$datetime<-strptime(myDat$X,format="%Y-%m-%d %H:%M:%S")
plot(myDat$datetime,rnorm(7),type="b")

Note that I have corrected what I think is a mistake in reading in
your data. The first date has been converted into the field name by
prepending an "X" and then replacing the hyphen and semicolon
characters with periods to coerce it to a name.  I changed that back
to what I think it was and this produces s basic plot with the dates
on the abscissa and some random numbers on the ordinate.

Jim

On Wed, Mar 17, 2021 at 6:26 AM Gregory Coats via R-help
<r-help at r-project.org> wrote: