[R] Time series labeling with Zoo

Gabor Grothendieck ggrothendieck at gmail.com
Fri Jun 23 07:54:41 CEST 2006


When the axis labelling does not work well you will have to do it yourself
like this.  The plot statement is instructed not to plot the axis and then
we extract into tt all the dates which are day of the month 1.  Then
we manually draw the axis using those.

library(zoo)
set.seed(1)
z <- zoo(runif(10), as.Date("2005-06-01") + 0:380)

plot(z, xaxt = "n")
tt <- time(z)[as.POSIXlt(time(z))$mday == 1]
axis(1, tt, format(tt, "%d%b%y"))

On 6/22/06, Gad Abraham <g.abraham at ms.unimelb.edu.au> wrote:
> Hi,
>
> I'm using zoo because it can automatically label the months of a time
> series composed of daily observations.
>
> This works well for certain time series lengths, but not for others, e.g.:
>
> While:
>
>  > library(zoo)
>  > plot(zoo(runif(10), as.Date("2005-06-01") + 0:50))
>
> Shows up the months and day of month,
>
>  > plot(zoo(runif(10), as.Date("2005-06-01") + 0:380))
>
> results in a single label "2006" in the middle of the x axis, with no
> months labelled, although there's plenty of room for labels.
>
>
> How do I get zoo to label the months too, without having to manually
> work out which day was the first day of each month?
>
>
> I'm using zoo 1.0-3 with R 2.2.1.
>
> Thanks,
> Gad
>
> --
> Gad Abraham
> Department of Mathematics and Statistics
> University of Melbourne
> Parkville 3010, Victoria, Australia
> email: g.abraham at ms.unimelb.edu.au
> web: http://www.ms.unimelb.edu.au/~gabraham
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



More information about the R-help mailing list