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. 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?... Sincerely, Halld??r ------------------------------------------ Halldor Bjornsson (halldor at vedur.is) Vedurstofa Islands (Icelandic Met. Office) Bustadavegur 9, IS-150, Reykjavik, Iceland
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
Halldor Björnsson <halldor <at> vedur.is> writes: : : 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. If you issue the command plot(x, ...whatever...) it will wind up calling plot.foo if class(x) is "foo". You can find the possibilities via: methods(plot) To view the starred ones on the output from the above you have to do somethingk like this assuming you want to look at the source for plot.acf: stats:::plot.acf (since plot.acf is from the stats package). : : 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?... : : Sincerely, : Halldór : This really looks like a time series so you probably really want to treat it that way, not as a data frame. library(zoo) z <- zoo(y, novdate) plot(z)