Skip to content
Prev 23153 / 63424 Next

Matplot does not work with x being POSIXt class (PR#9412)

gregor.gorjanc at bfro.uni-lj.si wrote:
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...