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

From: Don MacQueen <>
Date: Thu 07 Dec 2006 - 21:02:11 GMT

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, wrote:
>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
>x <- Sys.Date() - c(1:10)
>y <- cbind(1:10, 10:1)
>## [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.

This is very easy to obtain:

# x is a Date object


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

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.

>Thank you!


Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA mailing list Received on Sat Dec 09 17:50:25 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 Sat 09 Dec 2006 - 15:31:00 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.