On 7/30/07, Patrick Drechsler <[EMAIL PROTECTED]> wrote:
> Hi,
>
> what is the recommended way of adding a strip to a lattice plot?

See ?strip.default.

> In the example below I would like to add the value of mean(y) to a new
> strip.:
>
> --8<---------------cut here---------------start------------->8---
> library(lattice)
>
> ## Small sample data set:
> p0 <- xyplot(uptake ~ Type | Treatment, data = CO2)
>
> p1 <- update(p0,
>              panel = function(x, y, ...) {
>                panel.xyplot(x, y)
>                panel.abline(h = mean(y),
>                             col = "red"
>                             )
>              }
>              )
>
> plot(p1)
> --8<---------------cut here---------------end--------------->8---

That's not what strips are for. Strips are used for showing
information about the levels of conditioning variables. You can
instead do something like this:

update(p0,
       panel = function(x, y, ...) {
           require(grid)
           panel.xyplot(x, y, ...)
           panel.abline(h = mean(y), col = "red")
           grid.text(round(mean(y), 3), 0.5, 1, vjust = 1.2)
       })

The text can be put into a rectangle, to make them look like strips,
and you could use a prepanel function to make sure there's enough
space for it. Look up grid documentation for details.

There are other workarounds, e.g., using 'trellis.focus' and
'lattice.panelArgs'.

-Deepayan

______________________________________________
R-help@stat.math.ethz.ch 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.

Reply via email to