[R] histogram() with "Date" class?

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri May 9 21:48:05 CEST 2008


On 5/9/08, Ola Caster <ola.caster at gmail.com> wrote:
>
> Sorry for spamming the list...
>
>
> I noticed that if you first produce a date histogram with the hist()
> function, like this:
>
> basic.histogram <- hist(my.data$date, breaks = "months", plot = FALSE)
>
> and then try to transfer the breaks from that histogram to a lattice
> equivalent, like this:
>
> histogram(~date, data=my.data, breaks=basic.histogram$breaks)
>
> then I get a histogram that looks exactly like the original one, except the
> bins are not placed correctly on the x-axis. In my case they were all
> shifted almost a year to the right. Does anyone know why this happened and
> if there is a way to deal with it?

I can't comment on what you see unless you give us a reproducible
example, but I only see a shift in the label positions (so the labels
are different, but still accurate in both cases). For example,

foo <- Sys.Date() + 10 * rnorm(100)
bar <- hist(foo, breaks = "months")
dev.new()
histogram(~foo, breaks = bar$breaks,
          scales = list(x = list(format = "%b %d")))

-Deepayan



More information about the R-help mailing list