[Rd] error in lattice formattedTicksAndLabels.Date (PR#9590)

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri Mar 30 23:59:51 CEST 2007


On 3/29/07, jszinger at gmail.com <jszinger at gmail.com> wrote:
> Full_Name: James Szinger
> Version: 2.4.1
> OS: linux and MacOS X
> Submission from: (NULL) (128.165.24.206)

Bugs in packages are supposed to go to package maintainers, not r-bugs.

> I'm trying to plot some data from the past 12 months and the lattice package is
> not labeling the time axis correctly.  It shows only two labels instead of the
> expected 12.  The base graphics get it right.
>
> I think the problem is the commented-out line in formattedTicksAndLabels.Date in
> lattice's axis.R:
>     ## z <- c(range, x[is.finite(x)])

Why do you think so? This has nothing to do with it.

> The following example demonstrates the problem:
>
> require(lattice)  #lattice_0.14-16
>
> x <- rnorm(12)
> t <- seq( as.Date("2006-04-01"),by="month", length=12)
>
> plot(x~t)      # Has labels "May", "Jul", "Sep", "Nov", Jan", "Mar"
> xyplot(x~t)    # Has labels "Jan", "Mar"

The problem is in the nuances of the algorithm used. You can trigger
the same behavior with base graphics by mimicking what's happening
internally in lattice:

> tt = lattice:::extend.limits(range(t))
> tt
[1] "2006-03-08" "2007-03-24"
> plot(range(x) ~ tt, xaxs = "i")

There is a fundamental difference in how base and lattice handle axis
annotation. In particular, base uses all the data to determine tick
positions, while lattice uses only the range. This is hard to change
given how lattice comes up with a common range combining different
panels. It might still be possible to get around this, but don't
expect a quick solution.

(You can of course specify tick positions explicitly using 'scales')

-Deepayan



More information about the R-devel mailing list