[R] axis.POSIXct: Datetime data and plotting

About this list Date view Thread view Subject view Author view Attachment view

From: Barrowman, Nick (NBarrowman@cheo.on.ca)
Date: Fri 28 May 2004 - 04:10:09 EST


Message-id: <E2AD017CFE22764998D37A6026B8A01D46B3C8@exchsrv1.cheo.int>

I've run into a problem with the datetime axis generated by axis.POSIXct. It appears a similar issue was discussed in October 2003 under the subject line "datetime data and plotting" (see https://stat.ethz.ch/pipermail/r-help/2003-October/039071.html), but I wasn't able to determine whether there is a straightforward solution.

The code below produces a graph with apparently contradictory date labels on the top and bottom axes:

f <- "%Y/%m/%d"
d <- as.POSIXct(strptime(c("2003/1/15","2003/1/16",
  "2003/1/17","2003/1/18","2003/1/19"),format=f))
plot(d,1:length(d),axes=F);box()
axis(2)
abline(v=d[3])
axis.POSIXct(1,d,format=f)
axis.POSIXct(3,at=d,format=f)

On my copy of R (I have appended the version information below my signature), this produces a graph with a vertical line that lines up with "2003/01/17" on the top axis, but not on the bottom axis.

The issue seems to relate to time zones: here's what d looks like on my computer:

> d
[1] "2003-01-15 Eastern Standard Time"
[2] "2003-01-16 Eastern Standard Time"
[3] "2003-01-17 Eastern Standard Time"
[4] "2003-01-18 Eastern Standard Time"
[5] "2003-01-19 Eastern Standard Time"

(Actually I'm on Eastern Daylight Time, but let's ignore that for now.)

Changing the axes to display not only the date but also the time shows what's going on:

f <- "%Y/%m/%d"
f2 <- "%Y-%m-%d %H:%M"
d <- as.POSIXct(strptime(c("2003/1/15","2003/1/16",
  "2003/1/17","2003/1/18","2003/1/19"),format=f))
plot(d,1:length(d),axes=F);box()
axis(2)
abline(v=d[3])
axis.POSIXct(1,d,format=f2)
axis.POSIXct(3,at=d,format=f2)

The bottom axis put the ticks at 19:00 on each date. This seems an odd time until you note that Eastern Standard Time is 5 hours behind UTC, so 19:00 EST is 00:00 UTC.

But is there any easy way to avoid this problem? It is confusing and inconvenient that axis.POSIXct(1,d,format=f) and axis.POSIXct(3,at=d,format=f) give seemingly contradictory scales.

Many thanks for any help!

Nick Barrowman, Ph.D.
Chief Biostatistician, Chalmers Research Group
Children's Hospital of Eastern Ontario Research Institute
401 Smyth Road, Ottawa, Ontario, K1H 8L1, Canada
Tel (613) 737-7600 ext. 3971
Fax (613) 738-4800
Email nbarrowman@cheo.on.ca
URL www.chalmersresearch.com

> version
         _
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 1
minor 9.0
year 2004
month 04
day 12
language R

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:13 EST