From deepayan.sarkar at gmail.com  Fri Mar 30 23:59:51 2007
From: deepayan.sarkar at gmail.com (Deepayan Sarkar)
Date: Fri, 30 Mar 2007 14:59:51 -0700
Subject: [Rd] error in lattice formattedTicksAndLabels.Date (PR#9590)
In-Reply-To: <20070329161024.DE9455DE81@slim.kubism.ku.dk>
References: <20070329161024.DE9455DE81@slim.kubism.ku.dk>
Message-ID: <eb555e660703301459o78faca6fna2cb31b67869909f@mail.gmail.com>

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



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