An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110729/950723cd/attachment.pl>
Multifactor boxplots
4 messages · Tom Wilding, PIKAL Petr, Dennis Murphy +1 more
Hi
Dear All
I would like to produce interaction boxplots and this seems to work:
par(mfrow=c(2,2))
A=sample(rnorm(50,50,10))
B=sample(rnorm(50,100,10))
Test=merge(A,B,by=0)#by=0 where 0 is the row.names
TreatA=(gl(2,50,100,labels=c("High","Low")))
TreatB=rep(gl(2,25,50,labels=c("High","Low")),2)
Newdata=data.frame(TreatA,TreatB,Test)
bwplot(x~TreatA:TreatB,data=Newdata)
However, I would prefer the X axis labels to be different, such that
there
are two label rows (TreatA and TreatB) something like this: TreatA High High Low Low TreatB High Low High Low any guidance on achieving this much appreciated.
Combination of axes=FALSE
boxplot(x~TreatA:TreatB,data=Newdata, axes=F)
and following axis and mtext commands seems to do what you want
axis(2)
axis(1, at= 1:4,labels=c("H", "H", "L", "L"))
Regards
Petr
Regards Tom [[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org 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.
Hi:
Here are a couple of attempts, one with base graphics and one with lattice.
d <- data.frame(TreatA = gl(2, 50, 100, labels = c('High', 'Low')),
TreatB = rep(gl(2, 25, 50, labels = c('High', 'Low')), 2),
Test = c(rnorm(50, 50, 10), rnorm(50, 100, 10)))
lbl <- c('High\nHigh', 'High\nLow', 'Low\nHigh', 'Low\nLow')
# Lattice version:
library('lattice')
bwplot(Test ~ interaction(TreatA, TreatB), data = d,
scales = list(x = list(at = 1:4, label = lbl)))
trellis.focus('toplevel')
panel.text(0.08, 0.065, 'Treat A:\nTreat B:', cex = 0.75)
trellis.unfocus()
boxplot(Test ~ interaction(TreatA, TreatB), data = d, xaxt = 'n')
axis(1, at = 1:4, lab = lbl)
mtext('Treat A:\nTreat B:', side = 1, line = 1, at = 0)
You can adjust the position and size of the text to your taste. The
idea for the lattice plot comes from the following post in the list
archives:
http://r-project.markmail.org/search/?q=panel.text#query:panel.text+page:4+mid:2e3xpb2tsufntwya+state:results
HTH,
Dennis
On Fri, Jul 29, 2011 at 4:53 AM, Tom Wilding <Tom.Wilding at sams.ac.uk> wrote:
Dear All
I would like to produce interaction boxplots and this seems to work:
par(mfrow=c(2,2))
A=sample(rnorm(50,50,10))
B=sample(rnorm(50,100,10))
Test=merge(A,B,by=0)#by=0 where 0 is the row.names
TreatA=(gl(2,50,100,labels=c("High","Low")))
TreatB=rep(gl(2,25,50,labels=c("High","Low")),2)
Newdata=data.frame(TreatA,TreatB,Test)
bwplot(x~TreatA:TreatB,data=Newdata)
However, I would prefer the X axis labels to be different, such that there are two label rows (TreatA and TreatB) something like this:
TreatA ? ?High ? ? High ? ?Low ? ? ? Low
TreatB ? ?High ? ? Low ? ? High ? ? ?Low
any guidance on achieving this much appreciated.
Regards
Tom
? ? ? ?[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org 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.
On Jul 29, 2011, at 8:05 AM, Petr PIKAL wrote:
Hi
Dear All
I would like to produce interaction boxplots and this seems to work:
par(mfrow=c(2,2))
A=sample(rnorm(50,50,10))
B=sample(rnorm(50,100,10))
Test=merge(A,B,by=0)#by=0 where 0 is the row.names
TreatA=(gl(2,50,100,labels=c("High","Low")))
TreatB=rep(gl(2,25,50,labels=c("High","Low")),2)
Newdata=data.frame(TreatA,TreatB,Test)
bwplot(x~TreatA:TreatB,data=Newdata)
However, I would prefer the X axis labels to be different, such that
there
are two label rows (TreatA and TreatB) something like this: TreatA High High Low Low TreatB High Low High Low any guidance on achieving this much appreciated.
Combination of axes=FALSE
boxplot(x~TreatA:TreatB,data=Newdata, axes=F)
and following axis and mtext commands seems to do what you want
axis(2)
axis(1, at= 1:4,labels=c("H", "H", "L", "L"))
I didn't seem to get axes=FALSE to work the way I expected (or even
find it in boxplot or par documentation... oh, there it is in
plot.default) so also tried xaxt="n" and also tried to get the "over/
under" arrangement of the labels and "Treat"'s as specified:
boxplot(x~TreatA:TreatB,data=Newdata, xaxt="n")
axis(1, at= 1:4,labels=c("Treat A:High\nTreat B:High", "High\nLow",
"Low\nHigh", "Low\nLow"), padj=1 )
---End of answer---
<whine-mode on>
Now I have a question: If axes=FALSE is going to also suppress the
drawing of the box, shouldn't that be documented in the help page of
plot.default so that if someone (eventually) finds the right help page
they can develop the correct expectation? Yes, I can see that
frame.plot=axes is the default argument, but should we give the useR a
break and mention that in the Details?
And shouldn't the boxplot help page say that plot.default is
eventually called and give a link to it so that the available
graphical parameters are made known to the useR? Well, now that I
follow the ?bxp link I see that 'axes' is mentioned, but one is
further referred to ?plot.window which says _nothing_ about 'axes'.
But then in the code for bxp() I see that plot.default is not called
and that 'axes' are handled inside that function and nothing is passed
off to either plot.window or plot.default. <whine-mode off>
David Winsemius, MD West Hartford, CT