[R] Strange behavior with time-series x-axis
Allen McIntosh
mcintosh at research.telcordia.com
Thu Oct 25 21:59:38 CEST 2007
I recently called plot(x,y) where x was an array of POSIXct timestamps,
and was pleasantly surprised that it produced a nice plot right out of
the box:
z <- as.POSIXct(c("2006-10-26 08:00:00 EDT","2007-10-25 12:00:00 EDT"))
x <- seq(z[1],z[2],len=100)
y <- 1:100
plot(x,y,type="l")
The X axis had nice labels, one tick mark every other month. (Plotting
on a 1024x768 X11 display, Fedora Core 5, R version 2.5.1.)
What I really wanted to do was a little more elaborate, involving
multiple Y variables, so I did the following to draw the axes and frame
the plot:
plot(range(x),range(y),type="n")
and suddenly the nice X axis labels were not so nice anymore. There
were three tickmarks labeled "Nov", "Oct" and "Nov", and that's all.
(range(x) strips the tzone attribute from x, but replacing range(x) with
c(x[1],x[100]) doesn't change anything).
If x covers a slightly larger span of time, e.g.
z <- as.POSIXct(c("2006-10-1 08:00:00 EDT","2007-10-25 12:00:00 EDT"))
x <- seq(z[1],z[2],len=100)
plot(x,y,type="l")
then the x axis labeling is also problematic, consisting of a single
tick at "2007".
Is there anything I can do about this, short of turning off automatic X
labels and doing things myself?
More information about the R-help
mailing list