[R] plot with dates

Brian D Ripley ripley at stats.ox.ac.uk
Tue Dec 14 16:11:43 CET 2004


On Tue, 14 Dec 2004, [ISO-8859-1] Halldor Björnsson wrote:

>
> Hi,
> I am trying to understand the behaviour of the plot function.
> If I have
>
>   novdate <- as.Date("2001/11/1") + (0:29)
>   y <- 1:30
>   b <- data.frame(novdate,y)
>
> then plot(b$novdate,b$y) will produce a plot where the x-ticmarks are
> given as dates (Nov 04, Nov 09 etc), but plot(b) will produce a plot
> where the x-tickmars are integer values (#day since Jan 1st 1970)
>
> In the first case plot is getting a an x-vector of class Date, and
> y-vector of class integer.  In the second case plot gets an object of
> class data.frame (but with components of class Date and integer).
>
>
> I am new to R so I may be wrong about this, but it seems to me that
> different plotting methods are invoked. methods(plot) yields a list of
> plot methods, but I cannot access most of them.

You would be able to had you read the help page for methods().  E.g. use
getS3method("plot", "data.frame")  Or try ?plot.data.frame.

> Is there a way to guide plot(b) to using the method used by
> plot(b$novdate,b$y), - or is that a bad idea?...

It's the natural way to do so.  The plot method for data frames is really
designed for a quick look at multi-column numeric data frames.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list