From: Peter Ehlers <ehlers_at_ucalgary.ca>

Date: Sat, 09 Apr 2011 10:52:10 -0700

}

)

)

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. Received on Sat 09 Apr 2011 - 17:56:30 GMT

Date: Sat, 09 Apr 2011 10:52:10 -0700

On 2011-04-09 06:21, Dennis Murphy wrote:

*> Hi:
**>
*

> One hopes that there is a more elegant solution than this bit of ad-hockery.

*>> From your posted example:
**>
**> f1<- c(rep(c(rep("a", 3), rep("b", 3), rep("c", 3)), 2))
**> f2<- c(rep("A", 9), rep("B", 9))
**> dv<- c(0.9, 0.8, 0.85, 0.6, 0.65, 0.7, 0.8, 0.85, 0.8, 0.95, 0.85,
**> 0.9, 0.65, 0.7, 0.75, 0.85, 0.9, 0.85)
**> df<- data.frame(f1, f2, dv)
**> df$lab<- rep(1:6, each = 3)
**>
**> df$lab2<- ''
**> df$lab2[seq(1, 16, by = 3)]<- 1:6 # adapt to your situation - seq(1,
**> nrow(df) - 63, by = 64), perhaps
**>
**> bwplot(dv ~ f1 | f2, data = df, ylim = c(0.5, 1),
**> panel = function(x, y, ..., subscripts) {
**> lab<- df$lab2[subscripts]
**> panel.bwplot(x, y, ...)
**> panel.text(x, 0.55, labels = lab)
**> }
**> )
**>
**> Alternatively, panel.text() takes an alpha = argument; for example,
**>
**> bwplot(dv ~ f1 | f2, data = df, ylim = c(0.5, 1),
**> panel = function(x, y, ..., subscripts) {
**> lab<- df$lab[subscripts]
**> panel.bwplot(x, y, ...)
**> panel.text(x, 0.55, labels = lab, alpha = 0.5)
**> }
**> )
**>
**> You could toy with the value of alpha until something acceptable emerges.
**> But as I said, there is probably a better solution and I'm happy to be
**> educated if there is.
*

Here's a slight variation on your first solution which doesn't require the data to be appropriately sorted, using your df:

bwplot(dv ~ f1 | f2, data = df, ylim = c(0.5, 1), panel = function(x, y, ..., subscripts) {

lab <- df$lab[subscripts] lab[duplicated(lab)] <- "" panel.bwplot(x, y, ...) panel.text(x, 0.55, labels = lab)

}

)

and another variation which sets the text positions to NA for all but the first pass through the panel.text() function:

bwplot(dv ~ f1 | f2, data = df, ylim = c(0.5, 1), panel = function(x, y, ..., subscripts) { at.y <- rep(0.55, nrow(df)) is.na(at.y) <- which(duplicated(df$lab)) panel.bwplot(x, y, ...) panel.text(x, at.y[subscripts], labels = df$lab[subscripts])}

)

I think that the alpha argument is too one-off, i.e. dependent on how many levels in the boxplot.

Peter Ehlers

*>
*** > HTH,
**
> Dennis

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. Received on Sat 09 Apr 2011 - 17:56:30 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Sun 10 Apr 2011 - 13:20:29 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*