Hi, Using library(lattice), is there any way to tell xyplot to plot panels top to bottom, then left to right (i.e. panels are appended vertically, then horizontally). as.table changes the plot direction from left-to-right then top-to-bottom, to right-to-left then bottom- to-top, but that's not quite what I want to do. Thanks Yan
Richard M. Heiberger
2007-Jul-13 13:26 UTC
[R] Direction of panel plots in trellis graphics
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)] Rich
See this: http://tolstoy.newcastle.edu.au/R/help/06/08/32543.html and also the other messages in that thread. On 7/13/07, Yan Wong <h.y.wong at leeds.ac.uk> wrote:> Hi, > > Using library(lattice), is there any way to tell xyplot to plot > panels top to bottom, then left to right (i.e. panels are appended > vertically, then horizontally). as.table changes the plot direction > from left-to-right then top-to-bottom, to right-to-left then bottom- > to-top, but that's not quite what I want to do. > > Thanks > > Yan > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
deepayan.sarkar at gmail.com
2007-Jul-13 16:11 UTC
[R] Direction of panel plots in trellis graphics
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