Re: [R] Adding text labels to lattice plots with multiple panels

From: Jeff Stevens <stev0175_at_gmail.com>
Date: Tue, 12 Apr 2011 15:18:37 +0200

Hi Deepayan

Many thanks for bringing the which.packet() function to my attention--I missed it in the book. I do prefer that the panel function applies the labels to the data rather than adding them directly to the data in advance.

Jeff

On Tue, Apr 12, 2011 at 8:50 AM, Deepayan Sarkar <deepayan.sarkar_at_gmail.com> wrote:
> On Mon, Apr 11, 2011 at 12:49 AM, Jeff Stevens <stev0175_at_gmail.com> wrote:
>> Many thanks, Peter.  This works brilliantly, and I prefer to have the
>> labels assigned outside of panel function as well.
>
> You could also consider using which.packet(). You haven't explicitly
> told us how the labels are matched with the boxplots, but assuming
> that the labels are in the order of plotting, you can do [using the
> original data]:
>
>
> df <- data.frame(f1, f2, dv)
> lab <- c(1, 2, 3, 4, 5, 6)
>
> bwplot(dv ~ f1 | f2, data = df, ylim = c(0.5, 1),
>       text.labels = as.character(lab),
>       panel = function(x, y, ..., text.labels) {
>           panel.bwplot(x, y, ...)
>           n <- nlevels(x)
>           i <- seq_len(n) + (which.packet() - 1) * n
>           print(text.labels[i])
>           panel.text(x = seq_len(n), y = 0.55,
>                      labels = text.labels[i])
>       })
>
> -Deepayan
>



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 Tue 12 Apr 2011 - 13:21:18 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 Tue 12 Apr 2011 - 14:30:31 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.

list of date sections of archive