Alex Brown
2007-Jul-30 16:51 UTC
[R] duplicate DATE at in lattice scale handled differently from base graphics OR lattice numeric scales
When at, label chains contain duplicate at values, axis ticks are dropped. I believe this is handled incorrectly for Date ats in lattice 0.15-4 when compared to how it is handled for numeric, or for dates in base plot. This can result in mis-labelled axes in some circumstances. I have included executable examples. R: 2.5.0 numeric base plot: plot(1:10, axes=F); axis(1, at=c(2,4,4,6), labels=letters[1:4]) shows labels a, b, d date scale in base plot: plot((as.Date("2007-01-01") + 1:10), 1:10, axes=F); axis(1, at= (as.Date("2007-01-01")+c(2,4,4,6)), labels=letters[1:4]) shows labels a, b, d numeric scale in lattice plot xyplot(1:10 ~ 1:10, scales=list(x=list(relation="free", at=c (2,4,4,6), labels=list(letters[1:4])))) shows labels a, b, d date scale in lattice plot xyplot(1:10 ~ (as.Date("2007-01-01") + 1:10) , scales=list(x=list (relation="free", at=list(as.Date("2007-01-01")+c(2,4,4,6)), labels=list(letters[1:4])))) shows labels a, b, c Since this results in label c being placed at position 6, not 4, I feel this is a bug. -Alex Brown
Deepayan Sarkar
2007-Jul-31 01:27 UTC
[R] duplicate DATE at in lattice scale handled differently from base graphics OR lattice numeric scales
On 7/30/07, Alex Brown <alex at transitive.com> wrote:> When at, label chains contain duplicate at values, axis ticks are > dropped. I believe this is handled incorrectly for Date ats in > lattice 0.15-4 when compared to how it is handled for numeric, or for > dates in base plot. This can result in mis-labelled axes in some > circumstances. I have included executable examples. > > R: 2.5.0 > > numeric base plot: > > plot(1:10, axes=F); axis(1, at=c(2,4,4,6), labels=letters[1:4]) > > shows labels a, b, d > > date scale in base plot: > > plot((as.Date("2007-01-01") + 1:10), 1:10, axes=F); axis(1, at> (as.Date("2007-01-01")+c(2,4,4,6)), labels=letters[1:4]) > > shows labels a, b, dHowever,> foo = as.Date("2007-01-01") > plot(foo + 1:10, 1:10, axes = FALSE) > axis.Date(1, at = foo + c(2,4,4,6), labels = letters[1:4])Error in axis(side, at = z, labels = labels, ...) : 'at' and 'labels' lengths differ, 3 != 4 And this code is used almost unchanged in lattice, leading to> str(lattice:::formattedTicksAndLabels.Date(range(foo + 1:10), at = foo + c(2, 4, 4, 6), labels = letters[1:4]))List of 4 $ at : num [1:3] 13516 13518 13520 $ labels : chr [1:4] "a" "b" "c" "d" $ check.overlap: logi FALSE $ num.limit : num [1:2] 13515 13524 That is, 'at' is now of length 3 (and unlike axis.Date, this does not subsequently cause an error, which probably would have been preferable). I will add a fix. -Deepayan> numeric scale in lattice plot > > xyplot(1:10 ~ 1:10, scales=list(x=list(relation="free", at=c > (2,4,4,6), labels=list(letters[1:4])))) > > shows labels a, b, d > > date scale in lattice plot > > xyplot(1:10 ~ (as.Date("2007-01-01") + 1:10) , scales=list(x=list > (relation="free", at=list(as.Date("2007-01-01")+c(2,4,4,6)), > labels=list(letters[1:4])))) > > shows labels a, b, c > > Since this results in label c being placed at position 6, not 4, I > feel this is a bug. > > -Alex Brown