[R] x-axis labels for barplot of zoo object

Gabor Grothendieck ggrothendieck at gmail.com
Thu Jul 8 12:42:24 CEST 2010


On Thu, Jul 8, 2010 at 4:17 AM, Rainer M Krug <r.m.krug at gmail.com> wrote:
> Hi
>
> Let's assume, I have a dataset of 1000 datapoints, which represent daily
> recordings of a measurement.
> They are stored as a ts object (see example below)
>
> Now I want to represent them as a barplot. I found the barplot in the zoo
> package, but I have one problem: the x-axis labels. I would like to have the
> x-axis labels as either years only (located at the beginning of the year),
> or year/month. So my question:
>
> How can I set the x-axis labels to years
>
> I can change the start / end of the time series if necessary or use another
> barplot.
>
> Below find a small example:
>
> library(zoo)
> x <- ts(runif(1000), start=c(2000, 150), frequency=365)
> barplot(zoo(x))
>
>

Try this:

library(zoo)
plot(as.zoo(x), type = "h", xaxt = "n")
axis(1, unique(floor(time(x))))

or this:

plot(x, type = "h", xaxt = "n")
axis(1, unique(floor(time(x))))



More information about the R-help mailing list