Bengoechea Bartolomé Enrique (SIES 73)
2008-May-27 11:16 UTC
[R] Lattice zoo plot: no x ticks on first panel
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
Hi, Try this. Regards. library(zoo) library(lattice) my.axis <- function(side, ...) if (side != "top") axis.default(side, ...) my.panel <- function(..., side) { panel.axis(outside = TRUE, lab = FALSE) panel.plot.default(...) } my.par = list(clip = list(panel = "off", strip = "off")) set.seed(1) z <- zoo(cbind(a = 1:5, b = 11:15, c = 21:25) + rnorm(5)) xyplot(z, between = list(x = 1.2, y = 1), par.settings = my.par, axis = my.axis, panel = my.panel) On Tue, May 27, 2008 at 7:16 AM, Bengoechea Bartolom? Enrique (SIES 73) <enrique.bengoechea at credit-suisse.com> wrote:> 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 > > ______________________________________________ > 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. >
Bengoechea Bartolomé Enrique (SIES 73)
2008-May-27 15:41 UTC
[R] Lattice zoo plot: no x ticks on first panel
With some tweaking, this has fully solved the issue. Many thanks Gabor!! Regards, Enrique> -----Original Message----- > From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com] > Sent: martes, 27 de mayo de 2008 16:07 > To: Bengoechea Bartolom? Enrique (SIES 73) > Cc: r-help at r-project.org > Subject: Re: [R] Lattice zoo plot: no x ticks on first panel > > Hi, Try this. Regards. > > > library(zoo) > library(lattice) > > my.axis <- function(side, ...) if (side != "top") > axis.default(side, ...) > > my.panel <- function(..., side) { > panel.axis(outside = TRUE, lab = FALSE) > panel.plot.default(...) > } > > my.par = list(clip = list(panel = "off", strip = "off")) > > set.seed(1) > z <- zoo(cbind(a = 1:5, b = 11:15, c = 21:25) + rnorm(5)) > xyplot(z, between = list(x = 1.2, y = 1), par.settings = my.par, > axis = my.axis, panel = my.panel) >