[R] change axis format for different panels in xyplot in lattice
Deepayan Sarkar
deepayan.sarkar at gmail.com
Tue Nov 22 20:47:20 CET 2005
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
More information about the R-help
mailing list