[R] Lattice zoo plot: no x ticks on first panel
Bengoechea Bartolomé Enrique (SIES 73)
enrique.bengoechea at credit-suisse.com
Tue May 27 13:16:26 CEST 2008
Hi all,
I want to use lattice v0.17-4 on R 2.6.2 to draw a panel of time series of zoo objects (zoo v1.5-0). Everything works until I try to separate panels a bit and show only the bottom axis line with tick marks on every panel (but not axis labels, which I want only on the bottom panels).
I've tried several approachs, and the best I've got for showing only the bottom axis line and ticks is to set the 'axis.line' color in 'par.settings' to "transparent", then build the axis manually invoking panel.abline() and panel.axis() on a custom panel function. The problem is that, with this combination of parameters, axis ticks are never drawn on the *first* panel (bottom or top depending on the value of 'as.table'), but are correctly shown in all other panels.
I can overcome the problem using trellis.focus() and panel.axis() after drawing the panels, but it does not update the resulting trellis object, which I need to store for later printing/plotting, so I think I need to do it on the custom panel function (unless I'm missing some other feature of lattice...)
Below is the minimal code I've found to replicate the issue, as well as my environment configuration. Any help appreciated.
Best,
Enrique
--------------------------------------------------------------------------------------------------------------------------------------------
library(lattice)
library(grid)
library(zoo)
my.panel <- function(x, y, subscripts, groups, panel=panel.xyplot, ...) {
opar <- trellis.par.get("clip");
trellis.par.set(clip=list(panel="off", strip="off"));
on.exit(trellis.par.set(opar));
panel.abline(h=current.panel.limits()$ylim[1], col="black", lwd=1, lty=1);
lAxis <- lattice:::calculateAxisComponents(x);
panel.axis(side="bottom", line.col="black", at=lAxis$at,
ticks=TRUE, draw.labels=FALSE, outside=TRUE, check.overlap=FALSE);
panel.plot.default(x=x, y=y, subscripts=subscripts, groups=groups, panel=panel, ...);
}
z <- zoo(cbind(a = 1:5, b = 11:15, c = 21:25) + rnorm(5))
zoo:::xyplot.zoo(z, panel=my.panel, between=list(x=1.2, y=1), par.settings=list(axis.line=list(col="transparent")))
--------------------------------------------------------------------------------------------------------------------------------------------
> sessionInfo()
R version 2.6.2 (2008-02-08)
i386-pc-mingw32
locale:
LC_COLLATE=Spanish_Spain.1252;LC_CTYPE=Spanish_Spain.1252;LC_MONETARY=Spanish_Spain.1252;LC_NUMERIC=C;LC_TIME=Spanish_Spain.1252
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] zoo_1.5-0 lattice_0.17-4 rcom_1.5-2.2
More information about the R-help
mailing list