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/
Duncan Mackay
2018-Apr-24 14:23 UTC
[R] [FORGED] Extracting specified pages from a lattice ("trellis") object.
Hi Rolf do you need to use the layout argument? The layout is conditioned by the levels of a or unique values if not a factor. easier with factor unique(dta$a) [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" data.frame( a= unique(dta$a), page = rep(1:3, ea = 4), col = 1:2,row = rep(1:2, ea = 2)) a page col row 1 a 1 1 1 2 b 1 2 1 3 c 1 1 2 4 d 1 2 2 5 e 2 1 1 6 f 2 2 1 7 g 2 1 2 8 h 2 2 2 9 i 3 1 1 10 j 3 2 1 11 k 3 1 2 12 l 3 2 2 I hope I have got the order right full dataset xyplot(y~x|a,data=dta) bar = xyplot(y~x|a,data = subset(dta, a %in% c("e","f","g","h")) )) print(bar) (missed the dotplot requirement) but principle is the same. you can use packet.number or which.packet if needed to make it simpler use par.settings to do colours lines etc as well as spacing. Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2350 -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Rolf Turner Sent: Tuesday, 24 April 2018 15:52 To: Paul Murrell Cc: r-help at r-project.org; deepayan.sarkar at r-project.org Subject: Re: [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 ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Paul Murrell
2018-Apr-27 01:27 UTC
[R] [FORGED] Extracting specified pages from a lattice ("trellis") object.
Hi Does this not do what you want ... ? allpages <- dotplot(variety ~ yield | year * site, data=barley, layout=c(2,2)) page2 <- allpages[1:2, 3:4] print(page2) Paul On 24/04/18 17:51, Rolf Turner wrote:> > 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. >-- 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/
Possibly Parallel Threads
- [FORGED] Extracting specified pages from a lattice ("trellis") object.
- [FORGED] 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
- Extracting specified pages from a lattice ("trellis") object.