Alex Brown
2008-Feb-05 16:37 UTC
[R] Inconsistent lattice scales$x$at,label behaviour for POSIXct
I have encountered the following behaviour in lattice in 2.6.1 (and 2.4.0) which differs depending upon the type you use. I believe the numeric behaviour to be correct, and the POSIXct behaviour to be in error. When the x data and x axis in a lattice graph are POSIXct, and when using scales$x$at and scales$x$labels to add custom labels: If the first visible at value is not the first specified at value (due to x limit settings), the first visible label nonetheless receives the first specified label, instead of the label corresponding to the first visible at. In the following example, at = baseval + 1:4, label = letters[1:4] I have set it up so that baseval + 1:2 are not visible in the graph for numeric and Date types, the visible labels are letters[3:4] - ie "c" "d" for POSIXct, the visible labels are letters[1:3] - "a" "b". Simplest to show this by example: # numeric baseval=0; xyplot(1:10 ~ (baseval + 1:10) , scales=list(x=list (at=baseval+1:4, labels=letters[1:4])),xlim=baseval+c(3,10)) # Date baseval = as.Date("2007-01-01"); xyplot(1:10 ~ (baseval + 1:10) , scales=list(x=list (at=baseval+1:4, labels=letters[1:4])),xlim=baseval+c(3,10)) # POSIXct baseval = as.POSIXct("2007-01-01"); xyplot(1:10 ~ (baseval + 1:10) , scales=list(x=list (at=baseval+1:4, labels=letters[1:4])),xlim=baseval+c(3,10)) in particular, compare the Date and POSIXct versions -Alex Brown
Deepayan Sarkar
2008-Feb-05 20:59 UTC
[R] Inconsistent lattice scales$x$at, label behaviour for POSIXct
On 2/5/08, Alex Brown <alex at transitive.com> wrote:> I have encountered the following behaviour in lattice in 2.6.1 (and > 2.4.0) which differs depending upon the type you use. I believe the > numeric behaviour to be correct, and the POSIXct behaviour to be in > error. > > When the x data and x axis in a lattice graph are POSIXct, and when > using scales$x$at and scales$x$labels to add custom labels: > > If the first visible at value is not the first specified at value (due > to x limit settings), the first visible label nonetheless receives the > first specified label, instead of the label corresponding to the first > visible at.Yes, the relevant "POSIXct" method was subsetting 'at' to lie within the specified limits but not 'labels'. Should be fixed in the next update. Thanks, -Deepayan> In the following example, at = baseval + 1:4, label = letters[1:4] > > I have set it up so that baseval + 1:2 are not visible in the graph > > for numeric and Date types, the visible labels are letters[3:4] - ie > "c" "d" > > for POSIXct, the visible labels are letters[1:3] - "a" "b". > > > Simplest to show this by example: > > # numeric > > baseval=0; > xyplot(1:10 ~ (baseval + 1:10) , scales=list(x=list > (at=baseval+1:4, labels=letters[1:4])),xlim=baseval+c(3,10)) > > # Date > > baseval = as.Date("2007-01-01"); > xyplot(1:10 ~ (baseval + 1:10) , scales=list(x=list > (at=baseval+1:4, labels=letters[1:4])),xlim=baseval+c(3,10)) > > # POSIXct > > baseval = as.POSIXct("2007-01-01"); > xyplot(1:10 ~ (baseval + 1:10) , scales=list(x=list > (at=baseval+1:4, labels=letters[1:4])),xlim=baseval+c(3,10)) > > in particular, compare the Date and POSIXct versions > > -Alex Brown > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >