Rolf Turner
2018-Apr-14 00:25 UTC
[R] Extracting specified pages from a lattice ("trellis") object.
Suppose that (e.g.) xyplot() returns an object "xxx" with (say) 3 pages. I would like to extract/plot (print) just one of these pages, e.g. page 2. Here's a toy example: x <- rep(seq(0,1,length=11),12) set.seed(42) y <- rnorm(3*44) a <- rep(letters[1:12],each=11) dta <- data.frame(x=x,y=y,a=a) xxx <- xyplot(y~x|a,data=dta,layout=c(2,2)) I would to extract from xxx and print page 2 (the page corresponding to levels e, f, g and h). Is there any (simple) way that I can do this? I've mucked around with update.trellis() and [.trellis, but I cannot make head nor tail of the documentation. The [.trellis method seems to work in some situations, but not in others, and since I cannot understand what it actually does, I cannot figure out why. E.g. in my toy example "xxx[5:8]" seems to give me what I want, but in the context of my real application a similar construction does not work. Thanks for any insight. cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
Paul Murrell
2018-Apr-24 03:17 UTC
[R] [FORGED] Extracting specified pages from a lattice ("trellis") object.
Hi I think the subsetting works by giving you the panels for the corresponding levels of the conditioning variable(s). Note that, if there is more than one conditioning variable, you will need more than one subsetting index. For example, taking this plot with two conditioning variables and 12 panels in total ... dotplot(variety ~ yield | year * site, data=barley) ... this produces three pages ... dotplot(variety ~ yield | year * site, data=barley, layout=c(2,2)) ... and this produces the second page (both panels for the first conditioning variable and the third and fourth panels for the second conditioning variable) ... dotplot(variety ~ yield | year * site, data=barley, layout=c(2,2))[1:2, 3:4] Hope that helps Paul On 14/04/18 12:25, Rolf Turner wrote:> > Suppose that (e.g.) xyplot() returns an object "xxx" with (say) 3 pages. > I would like to extract/plot (print) just one of these pages, e.g. > page 2. > > Here's a toy example: > > x?? <- rep(seq(0,1,length=11),12) > set.seed(42) > y?? <- rnorm(3*44) > a?? <- rep(letters[1:12],each=11) > dta <- data.frame(x=x,y=y,a=a) > xxx <- xyplot(y~x|a,data=dta,layout=c(2,2)) > > I would to extract from xxx and print page 2 (the page corresponding to > levels e, f, g and h). > > Is there any (simple) way that I can do this? > > I've mucked around with update.trellis() and [.trellis, but I cannot > make head nor tail of the documentation.? The [.trellis method seems to > work in some situations, but not in others, and since I cannot > understand what it actually does, I cannot figure out why. > > E.g. in my toy example "xxx[5:8]" seems to give me what I want, but in > the context of my real application a similar construction does not work. > > Thanks for any insight. > > cheers, > > Rolf Turner >-- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/
Rolf Turner
2018-Apr-24 05:51 UTC
[R] [FORGED] Extracting specified pages from a lattice ("trellis") object.
On 24/04/18 15:17, Paul Murrell wrote:> Hi > > I think the subsetting works by giving you the panels for the > corresponding levels of the conditioning variable(s).? Note that, if > there is more than one conditioning variable, you will need more than > one subsetting index. > > For example, taking this plot with two conditioning variables and 12 > panels in total ... > > dotplot(variety ~ yield | year * site, data=barley) > > ... this produces three pages ... > > dotplot(variety ~ yield | year * site, data=barley, > ??????? layout=c(2,2)) > > ... and this produces the second page (both panels for the first > conditioning variable and the third and fourth panels for the second > conditioning variable) ... > > dotplot(variety ~ yield | year * site, data=barley, > ??????? layout=c(2,2))[1:2, 3:4] > > Hope that helps.Hmm. Thanks Paul. I may be able to work with that. But what I really wanted was to take bar <- dotplot(variety ~ yield | year * site, data=barley) and then do (something like) foo <- bar[<something>] so that foo contains only the second page of bar, and then do print(foo) to get a plot of (just) the second page. Without re-issuing a (modified) plot command. Is that not at all possible? cheers, Rolf. -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
Possibly Parallel Threads
- [FORGED] Extracting specified pages from a lattice ("trellis") object.
- [FORGED] Extracting specified pages from a lattice ("trellis") object.
- Extracting specified pages from a lattice ("trellis") object.
- lattice: showing panels for factor levels with no values
- change plotting symbol for groups in trellis graph