[R] Direction of panel plots in trellis graphics

deepayan.sarkar at gmail.com deepayan.sarkar at gmail.com
Fri Jul 13 18:11:23 CEST 2007


On 7/13/07, Richard M. Heiberger <rmh at temple.edu> wrote:
> You can control the panel sequence with subscripting and transpose.
> Here are several examples.  I think tmp.tr3 is the one you asked for.
>
> library(lattice)
>
> tmp <- data.frame(x=rnorm(24), y=rnorm(24), a=rep(letters[1:6],4),
> b=rep(LETTERS[1:4],each=6))
> tmp.tr <- xyplot(y ~ x | a*b, data=tmp)
> tmp.tr
> t(tmp.tr)
>
> tmp.tr2 <- xyplot(y ~ x | a, data=tmp)
> tmp.tr2
> tmp.tr2[c(1,3,5,2,4,6)]
>
> tmp.tr3 <- xyplot(y ~ x | a, data=tmp, as.table=TRUE)
> tmp.tr3
> tmp.tr3[c(1,3,5,2,4,6)]

Another high level option is to change the rule determining how
packets are chosen for a given panel in the layout.

print(tmp.tr3,
      packet.panel = function(layout, row, column, ...) {
          layout <- layout[c(2, 1, 3)]
          packet.panel.default(layout = layout,
                               row = column,
                               column = row, ...)
      })

This effectively transposes the layout, which (along with
as.table=TRUE) is what you want.

-Deepayan



More information about the R-help mailing list