[R] ltext - adding text to each panel from a matrix

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Nov 10 19:28:57 CET 2005


On 11/10/05, Andy Bunn <abunn at whrc.org> wrote:
> Hi all (really probably just Deepayan):
>
> In the plot below I want to add text on either side of each violin plot
> that
> indicates the number of observations that are either positive or negative.
> I'm trying to do this with ltext() and I've also monkeyed about with
> panel.text().

They are the same (at least for now).

> The code below is generally what I want but my calls to
> ltext() are wrong and I'm not sure how to fix them. Right now they
> replicate
> the first column of the matrices obs.pos and obs.neg for each panel. How do
> I tell ltext to advance to the next column when the next panel is plotted?
> I
> don't see how subscripts can do it, but I bet it's something along that
> line...

Maybe, but there's a more direct solution (somewhat artificial perhaps):

bwplot(treatment~foo|group, data = dat,
       panel=function(..., packet.number) {
           panel.violin(..., col = "transparent", varwidth = F)
           panel.abline(v=0, lty = "dotted")
           ltext(x.obs.pos, y.obs.pos, obs.pos[, packet.number], pos = 2)
           ltext(x.obs.neg, y.obs.neg, obs.neg[, packet.number], pos = 4)
       },
       par.strip.text = list(cex = 0.8),  xlim = my.xlim)

This is documented under 'panel' in ?xyplot.

Deepayan




More information about the R-help mailing list