levyr@umd.edu
2005-Nov-22 16:38 UTC
[R] change axis format for different panels in xyplot in lattice
Dear R users, My apologies for a simple question for which I suspect there is a simple answer that I have yet to find. I'd like to plot panels in lattice with different graphical parameters for the axes. For example, the code x<-rnorm(100) y<-rnorm(100) z<-c(rep(1,50), rep(2,50)) library(lattice) xyplot(y~x|z) plots two panels with the default black axes. Running the following code trellis.par.set(list(axis.line = list(col = "transparent"))) xyplot(y~x|z) plots the same data without the axes. Is it possible (in one plot) to plot the first panel with black axes and the second panel with tranparent axes? Thank you for your time and your attention, Roy
Deepayan Sarkar
2005-Nov-22 19:47 UTC
[R] change axis format for different panels in xyplot in lattice
On 11/22/05, levyr at umd.edu <levyr at umd.edu> wrote:> Dear R users, > > My apologies for a simple question for which I suspect there > is a simple answer that I have yet to find. I'd like to plot > panels in lattice with different graphical parameters for the > axes. For example, the code > > x<-rnorm(100) > y<-rnorm(100) > z<-c(rep(1,50), rep(2,50)) > library(lattice) > xyplot(y~x|z) > > plots two panels with the default black axes. Running the > following code > > trellis.par.set(list(axis.line = list(col = "transparent"))) > xyplot(y~x|z) > > plots the same data without the axes. Is it possible (in one > plot) to plot the first panel with black axes and the second > panel with tranparent axes?Not systematically, but consider this approach: library(grid) trellis.par.set(list(axis.line = list(col = "transparent"))) xyplot(y~x|z, panel = function(..., panel.number) { if (panel.number == 1) grid.rect(gp = gpar(col = 'black')) panel.xyplot(...) } ) This is probably not exactly what you want, since the tick marks are transparent in both panels, but you get the idea. You can gain finer control of the axis annotation using panel.axis inside your panel function (but you will need to disable clipping, controlled by trellis.par.get("clip")). Alternatively, check out ?trellis.focus. Deepayan
levyr@umd.edu
2005-Nov-29 00:50 UTC
[R] change axis format for different panels in xyplot in lattice
Utilizing panel.number and grid allowed me to do all my desired manipulations - thanks Deepayan! Roy ---- Original message ---->Date: Tue, 22 Nov 2005 13:47:20 -0600 >From: Deepayan Sarkar <deepayan.sarkar at gmail.com> >Subject: Re: change axis format for different panels inxyplot in lattice>To: levyr at umd.edu >Cc: r-help at stat.math.ethz.ch > >On 11/22/05, levyr at umd.edu <levyr at umd.edu> wrote: >> Dear R users, >> >> My apologies for a simple question for which I suspect there >> is a simple answer that I have yet to find. I'd like to plot >> panels in lattice with different graphical parameters for the >> axes. For example, the code >> >> x<-rnorm(100) >> y<-rnorm(100) >> z<-c(rep(1,50), rep(2,50)) >> library(lattice) >> xyplot(y~x|z) >> >> plots two panels with the default black axes. Running the >> following code >> >> trellis.par.set(list(axis.line = list(col = "transparent"))) >> xyplot(y~x|z) >> >> plots the same data without the axes. Is it possible (in one >> plot) to plot the first panel with black axes and the second >> panel with tranparent axes? > >Not systematically, but consider this approach: > >library(grid) >trellis.par.set(list(axis.line = list(col = "transparent"))) >xyplot(y~x|z, > panel = function(..., panel.number) { > if (panel.number == 1) grid.rect(gp = gpar(col 'black')) > panel.xyplot(...) > } ) > >This is probably not exactly what you want, since the tickmarks are>transparent in both panels, but you get the idea. You cangain finer>control of the axis annotation using panel.axis inside your panel >function (but you will need to disable clipping, controlled by >trellis.par.get("clip")). Alternatively, check out?trellis.focus.> >Deepayan