I am using R-1.7.0 and have some data which consist of one vector of numbers and a second corresponding vector of dates belonging to the POSIXct class. I would like to plot the numbers against the dates. What is the best way to do this? It almost works to just call `plot.' However if I do this while using the `ylab' parameter I get a warning message: parameter "ylab" couldn't be set in high-level plot() function Here is a function that demonstrates the behavior. ylabProblem <- function() { x <- ISOdate(2003, 4, 1:10) # POSIXct vector y <- rnorm(10) plot(x, y, ylab = 'I am y') } It works to invoke the low-level plotting routines by hand as follows: ylabNoProblem <- function() { x <- ISOdate(2003, 4, 1:10) # POSIXct vector y <- rnorm(10) plot.default(x, y, xaxt = 'n', xlab = '', ylab = 'I am y') axis.POSIXct(1, x) } But I don't like calling methods explicitly like this.
On Wed, Apr 30, 2003 at 03:10:52PM -0400, Ed Kademan wrote:> I am using R-1.7.0 and have some data which consist of one vector of > numbers and a second corresponding vector of dates belonging to the > POSIXct class. I would like to plot the numbers against the dates. > What is the best way to do this? > > It almost works to just call `plot.' However if I do this while using > the `ylab' parameter I get a warning message: > > parameter "ylab" couldn't be set in high-level plot() function > > Here is a function that demonstrates the behavior. > > ylabProblem <- function() { > x <- ISOdate(2003, 4, 1:10) # POSIXct vector > y <- rnorm(10) > plot(x, y, ylab = 'I am y') > } > > It works to invoke the low-level plotting routines by hand as follows: > > ylabNoProblem <- function() { > x <- ISOdate(2003, 4, 1:10) # POSIXct vector > y <- rnorm(10) > plot.default(x, y, xaxt = 'n', xlab = '', ylab = 'I am y') > axis.POSIXct(1, x) > } > > But I don't like calling methods explicitly like this.ylabThisWorks <- function() { x <- ISOdate(2003, 4, 1:10) # POSIXct vector y <- rnorm(10) plot(x,y, ann=FALSE) # use ann=F, not axes=F title(ylab="I am y") # and add the desired label } Hth, Dirk -- Don't drink and derive. Alcohol and algebra don't mix.
Ed Kademan wrote:> > I am using R-1.7.0 and have some data which consist of one vector of > numbers and a second corresponding vector of dates belonging to the > POSIXct class. I would like to plot the numbers against the dates. > What is the best way to do this? > > It almost works to just call `plot.' However if I do this while using > the `ylab' parameter I get a warning message: > > parameter "ylab" couldn't be set in high-level plot() functionIn this case, you can ignore that warning message (it's a warning, not an error).> Here is a function that demonstrates the behavior. > > ylabProblem <- function() { > x <- ISOdate(2003, 4, 1:10) # POSIXct vector > y <- rnorm(10) > plot(x, y, ylab = 'I am y') > } > > It works to invoke the low-level plotting routines by hand as follows: > > ylabNoProblem <- function() { > x <- ISOdate(2003, 4, 1:10) # POSIXct vector > y <- rnorm(10) > plot.default(x, y, xaxt = 'n', xlab = '', ylab = 'I am y') > axis.POSIXct(1, x) > } > > But I don't like calling methods explicitly like this.axis.POSIXct() is not a method, because axis() is not a generic function (and hence not able to dispatch for POSIXct objects). Calling axis.POSIXct() explicitly is a not a bad idea in this case. Uwe Ligges