[R] ylab in plot.POSIXct
Dirk Eddelbuettel
edd at debian.org
Wed Apr 30 21:36:23 CEST 2003
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.
More information about the R-help
mailing list