Re: [Rd] Matplot does not work with x being POSIXt class (PR#9412)

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Thu 07 Dec 2006 - 13:52:12 GMT

gregor.gorjanc@bfro.uni-lj.si wrote:
> Hi,
>
> Matplot works with x being Date class but not POSIXt. Here is the
> example with R version 2.5.0 Under development (unstable) (2006-12-06
> r40129)
>
> Example:
>
> x <- Sys.Date() - c(1:10)
> y <- cbind(1:10, 10:1)
> class(x)
> ## [1] "Date"
> matplot(x, y)
>
> x <- strptime(as.character(x), format="%Y-%m-%d")
> ## [1] "POSIXt" "POSIXlt"
> matplot(x, y)
> Error in matplot(x, y) : 'x' and 'y' must have only 1 or the same number
> of columns
>
> Additionally, matplot with x being Date class does not use apropriate
> annotation for x axis.
>
Matplot plots matrices, it is not a bug that it doesn't work with other objects. Rather, it is a coincidence that it works with dates when their internal representation is as numbers.

It might be a useful enhancement, but things are not so easy: The root of the issue is that matrices of time/date objects don't behave nicely. Try, e.g.

structure(matrix(1:10, 2), class = "Date") matrix(structure(1:10, class = "Date"), 2)

The former will actually work in the sense that it allows indexing, it just forgets about dimensions when printing. The latter throws away the class of x, and is used inside matplot() hence the annotation will not be that for a Date object.

Also, as.matrix.POSIXlt() does something completely different, so things get a bit tricky...



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Dec 09 04:54:50 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 08 Dec 2006 - 18:30:58 GMT.

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