Skip to content
Prev 23154 / 63421 Next

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

As Peter said, matplot plots matrices. The columns of a matrix are 
vectors of numbers. A POSIXlt object is not a vector of numbers, it 
is a list. So it shouldn't work. And should not be expected to work.

But with a POSIXct object it will work.

x <- strptime(as.character(x), format="%Y-%m-%d")
## [1] "POSIXt"  "POSIXlt"
matplot( as.POSIXct(x), y)
At 1:56 PM +0100 12/7/06, gregor.gorjanc at bfro.uni-lj.si wrote:
This is very easy to obtain:

# x is a Date object
matplot(x,y,xaxt='n')
axis.Date(1,x)

or

# x is a POSIXlt object
matplot( as.POSIXct(x), y,xaxt='n')
axis.POSIXct(1,x)

So easy, in fact, that I personally would not expect R core to spend 
time on it. One of the virtues of R is that the language is so rich 
that little tweaks like this are often very easy.
-Don