[Rd] date and plot problems

Gabor Grothendieck ggrothendieck at volcanomail.com
Thu Jun 19 12:46:19 MEST 2003


Consider the vector of POSIXlt dates:

	t5 <- as.POSIXlt(paste("2003/01",1:5,sep="/")

which gives the result:

	"2003-01-01" "2003-01-02" "2003-01-03" "2003-01-04" "2003-01-05"

Upon using this with plot:

	plot(t5,1:5)   # ***

the points do not appear above the days.  There appears to be two 
problems with this:

1. the POSIXlt datetime class has no concept of timezone but when
its passed to plot it implicitly gets converted to POSIXct which
does.  When that happens, it appears that GMT is used as the 
timezone rather than the current timezone so the dates are not
what you think they are.

2. the end of day is plotted above the x axis label rather
than the beginning of day.

The following workaround fixes both of these:

        plot(as.POSIXct(t5,tz="GMT")+24*60*60-1,1:5) 

The problems cited above are pretty subtle and deserve at least a 
mention and probably some changes.  Potential solutions include:

- adding a plot.POSIXlt method (to avoid unnecessarily introducing 
  time zones)

- adding date classes and methods (not just datetime classes and 
  methods) so plot can know how to proceed

- adding smarts to plot

- or perhaps these problems can be subsumed under generalizations
  to regular and irregular time series in some way

One other item.  The x axes labels for

        plot( t5[1:4], 1:4 )

need improvement.

(I am using R 1.7.1 on Windows 2000 Pro.)



More information about the R-devel mailing list