[Rd] plot(date, y) versus plot(y ~ date)

Duncan Murdoch murdoch@stats.uwo.ca
Fri Feb 14 20:17:02 2003

If "time" is a POSIXlt variable and "y" is numeric, then plot(time, y)
works but plot(y ~ time) doesn't.

For example, 

 time <- as.POSIXlt( Sys.time() + 1:100)
 y <- rnorm(100)
 plot(time,y)     # succeeds
 plot(y ~ time)  # fails

The reason for this is that there's a plot.POSIXlt method that
converts time to a POSIXct variable, and most of the plotting
machinery works fine on those.  Manual conversion to POSIXct will also
make the plot(y ~ time) version work.

Should this conversion be made automatically?  It looks like doing
something in the internal implementation of model.frame would be
necessary.  It's probably not a good idea to do something specific to
POSIXlt types, but what about attempting to coerce any unrecognized
object to double?  It's easy to implement as.double.POSIXlt.

Duncan Murdoch