Hello ! I'm struggling again against lattice graprhics. ;) I'm trying to produce a conditionnal xyplot with two conditionning factors (let's say A and B). I want the levels of those factors (A1, A2, etc) to show in the margins of the lattice plot, not in the strips between the panels. A1 A2 A3 plot11 plot12 plot13 B1 plot21 plot22 plot23 B2 I managed to remove the strips with strip=FALSE, but now I can't find how to write the levels of the factors in the margin in front of their respective lines/columns. It doesn't seems that xlab and ylab arguments could help doing this, as I can't insert multiple xlab's (x variable and A levels, or y variable and B levels) and can't decide which side to use for writing them. Does anybody have a hint ? Thank you very much ! -- Ir. Yves BROSTAUX Unit? de Statistique et Informatique Facult? universitaire des Sciences agronomiques de Gembloux (FUSAGx) 8, avenue de la Facult? B-5030 Gembloux Belgique T?l: +32 81 62 24 69 Email: brostaux.y at fsagx.ac.be
On Tuesday 22 March 2005 08:53, Yves Brostaux wrote:> Hello ! > > I'm struggling again against lattice graprhics. ;) I'm trying to > produce a conditionnal xyplot with two conditionning factors (let's > say A and B). I want the levels of those factors (A1, A2, etc) to > show in the margins of the lattice plot, not in the strips between > the panels. > > A1 A2 A3 > > plot11 plot12 plot13 B1 > > plot21 plot22 plot23 B2You cannot do this with xyplot (or any other lattice function). But try ?coplot. Deepayan> I managed to remove the strips with strip=FALSE, but now I can't find > how to write the levels of the factors in the margin in front of > their respective lines/columns. It doesn't seems that xlab and ylab > arguments could help doing this, as I can't insert multiple xlab's (x > variable and A levels, or y variable and B levels) and can't decide > which side to use for writing them. > > Does anybody have a hint ? Thank you very much !
Thank you for this advice. It does almost what I want, except that I need an extra "groups" argument because I have two separate groups of data to plot by their own line on each panel. I tried to solve it using the subscripts argument and custom panel function, but I still miss something : Data frame err.moy has 5 columns of interest. I want to plot moy against X conditionning on A and B, for the two groups stored in the factor Grp (coded by 1 and 2) in each panel. I tried coplot(moy~X|A*B, data=err.moy, panel=function(x, y, subscripts, ...) { lines(x[subscripts & err.moy[subscripts,]$Grp==1], y[subscripts & err.moy[subscripts,]$Grp==1], type="b", lty="dashed", pch=3) lines(x[subscripts & err.moy[subscripts,]$Grp==2], y[subscripts & err.moy[subscripts,]$Grp==2], type="b", lty="dotted", pch=2) }, subscripts=TRUE ) but nothing plot in the panels. Deepayan Sarkar a écrit :>On Tuesday 22 March 2005 08:53, Yves Brostaux wrote: > > >>Hello ! >> >>I''m struggling again against lattice graprhics. ;) I''m trying to >>produce a conditionnal xyplot with two conditionning factors (let''s >>say A and B). I want the levels of those factors (A1, A2, etc) to >>show in the margins of the lattice plot, not in the strips between >>the panels. >> >>A1 A2 A3 >> >>plot11 plot12 plot13 B1 >> >>plot21 plot22 plot23 B2 >> >> > >You cannot do this with xyplot (or any other lattice function). But >try ?coplot. > >Deepayan > > > >>I managed to remove the strips with strip=FALSE, but now I can''t find >>how to write the levels of the factors in the margin in front of >>their respective lines/columns. It doesn''t seems that xlab and ylab >>arguments could help doing this, as I can''t insert multiple xlab''s (x >>variable and A levels, or y variable and B levels) and can''t decide >>which side to use for writing them. >> >>Does anybody have a hint ? Thank you very much ! >> >> > > > >-- Ir. Yves BROSTAUX Unité de Statistique et Informatique Faculté universitaire des Sciences agronomiques de Gembloux (FUSAGx) 8, avenue de la Faculté B-5030 Gembloux Belgique Tél: +32 81 62 24 69 Email: brostaux.y@fsagx.ac.be [[alternative HTML version deleted]]
Hi Yves Brostaux wrote:> Hello ! > > I'm struggling again against lattice graprhics. ;) I'm trying to produce > a conditionnal xyplot with two conditionning factors (let's say A and > B). I want the levels of those factors (A1, A2, etc) to show in the > margins of the lattice plot, not in the strips between the panels. > > A1 A2 A3 > > plot11 plot12 plot13 B1 > > plot21 plot22 plot23 B2 > > > I managed to remove the strips with strip=FALSE, but now I can't find > how to write the levels of the factors in the margin in front of their > respective lines/columns. It doesn't seems that xlab and ylab arguments > could help doing this, as I can't insert multiple xlab's (x variable and > A levels, or y variable and B levels) and can't decide which side to use > for writing them. > > Does anybody have a hint ? Thank you very much !Here's one approach, using trellis.focus() and grid.text(). This particular example is obviously hand-tuned to the example data set, but it shouldn't be too hard to generalise. I don't think you can do this via a panel function because output is clipped to the current panel for panel functions (Deepayan Sarkar may be able to confirm or deny that). # "standard" dotplot dotplot(variety ~ yield | year * site, data=barley) # Customised version library(grid) # lattice plot without strips dotplot(variety ~ yield | year * site, data=barley, strip=FALSE) # move to panel (1, 6) and turn clipping off so can draw outside panel trellis.focus("panel", 1, 6, clip.off=TRUE, highlight=FALSE) # draw factor label 2 lines above the top of the panel grid.text("1932", y=unit(1, "npc") + unit(2, "lines")) # move to next panel, repeat ad nauseam trellis.focus("panel", 2, 6, clip.off=TRUE, highlight=FALSE) grid.text("1931", y=unit(1, "npc") + unit(2, "lines")) grid.text("Waseca", x=unit(1, "npc") + unit(1, "lines"), rot=90) trellis.focus("panel", 2, 5, clip.off=TRUE, highlight=FALSE) grid.text("Crookston", x=unit(1, "npc") + unit(1, "lines"), rot=90) trellis.focus("panel", 2, 4, clip.off=TRUE, highlight=FALSE) grid.text("Morris", x=unit(1, "npc") + unit(1, "lines"), rot=90) trellis.focus("panel", 2, 3, clip.off=TRUE, highlight=FALSE) grid.text("University Farm", x=unit(1, "npc") + unit(1, "lines"), rot=90) trellis.focus("panel", 2, 2, clip.off=TRUE, highlight=FALSE) grid.text("Duluth", x=unit(1, "npc") + unit(1, "lines"), rot=90) trellis.focus("panel", 2, 1, clip.off=TRUE, highlight=FALSE) grid.text("Grand Rapids", x=unit(1, "npc") + unit(1, "lines"), rot=90) Paul -- 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/