Re: [R] datetime on x-axis of plot

From: Steve Revilak <steve_at_srevilak.net>
Date: Fri, 29 Feb 2008 21:22:38 -0500 (EST)


> From: joshv

> Hello, I'm reading Time Series Analysis and its Applilcations with R Examples
> and I have a question...
>
> I notice that in the book there are timeseries plots but without the x-axis
> being labeled with dates. They are just numbers 1,...50,...100, etc. How
> do I get the date to show up on the x-axis?
>
> Here is my dateframe:
>
> > head(myData, 5)
>
> 1 2008-01-30 08:30 7.00
> 2 2008-01-30 08:32 9.25
> 3 2008-01-30 08:34 5.50
> 4 2008-01-30 08:36 5.00
> 5 2008-01-30 08:38 -26.25

Try this:

   # "foo.dat" is a two-column file with the data you gave earlier    myData <- read.table("foo.dat", sep="\t", colClasses=c("POSIXct", "numeric"))

   # plot, but don't label the x-axis
   plot(myData, type="l", xaxt="n")

   # now, add labels to the x-axis
   axis.POSIXct(1, myData$V1, format="%m/%d %H:%M")

Steve



R-help_at_r-project.org mailing list
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. Received on Sat 01 Mar 2008 - 02:21:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 01 Mar 2008 - 04:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive