Chris Behr
2006-Feb-08 21:14 UTC
[R] bwplot: how to display response variables separately in same panel?
Hi - I have two response variables 'y1' and 'y2' and a factor 'x'. I would like to create paired box-whiskers plots for y1~x and y2~x and labeled for the same x. the b-w plots would be side-by-side in the same panel - almost like a barchart with two parallel columns for the same x. the code 'bwplot(y1+y2~x, outer=T)' gives me two side-by-side panels. this is ok, but not exactly what i am looking for. any ideas? thanks, chris Christopher Behr Principal Analyst eDesign Dynamics www.edesigndynamics.com 4024 Calvert St. NW Washington DC 20007 (202) 298-6437 (t/f) (551) 998-4823 (c)
Deepayan Sarkar
2006-Feb-09 01:10 UTC
[R] bwplot: how to display response variables separately in same panel?
On 2/8/06, Chris Behr <cbehr at edesigndynamics.com> wrote:> Hi - > > I have two response variables 'y1' and 'y2' and a factor 'x'. I would like > to create paired box-whiskers plots for y1~x and y2~x and labeled for the > same x. the b-w plots would be side-by-side in the same panel - almost like > a barchart with two parallel columns for the same x. > > the code 'bwplot(y1+y2~x, outer=T)' gives me two side-by-side panels. this > is ok, but not exactly what i am looking for. > any ideas?Unless you want to write your own panel function, you need to start by coercing the data into the `long' format, e.g. df <- data.frame(y = c(y1, y2), x = rep(x, 2), which = gl(2, length(x))) Then you can probably do [untested] bwplot(y ~ which | x, df, layout = c(nlevels(x), 1)) or bwplot(y ~ x:which, df) Deepayan