Re: [R] adding error bars to lattice plots

From: Deepayan Sarkar <deepayan.sarkar_at_gmail.com>
Date: Fri 13 Oct 2006 - 21:46:15 GMT

On 10/13/06, Daniel E. Bunker <deb37@columbia.edu> wrote:
> Dear Deepayan and Sundar,
>
> Thank you so much for your help with this. However, I may have phrased
> my problem too specifically, assuming that *in general* I could apply
> your response to all Lattice graphics.
>
> What I need is a barchart or vertical dotchart, with error bars, across
> three treatments, with a form that should look something like:
> barchart(median~fac1|by1, groups=group1).
>
> Your solution works great with the problem I had posed
> <xyplot(voice.part ~ median|by1, groups=group1, [snip]>, yet when I
> switch the axes for a vertical dotchart <xyplot(median~voice.part|by1,
> groups=group1, [snip]> the error bars remain horizontal and do not
> follow the switched axes.
>
> I tried to alter all 'lx' and 'ux' to 'ly' and 'uy' in panel.ci and
> prepanel.ci, but to no avail. I'm afraid I have not (YET) managed to
> understand just how Lattice works.
>
> Re. moving panel.abline() from panel.groups to panel, does that mean I
> need to rewrite panel.superpose?

Only if you consider writing a function B that uses function A rewriting function A.

> Again, any advice would be greatly appreciated.

Continuing with the singer example, the following works for me:

prepanel.ci <- function(x, y, ly, uy, subscripts, ...) {

    y <- as.numeric(y)
    ly <- as.numeric(ly[subscripts])
    uy <- as.numeric(uy[subscripts])
    list(ylim = range(y, uy, ly, finite = TRUE)) }

panel.ci <- function(x, y, ly, uy, subscripts, pch = 16, ...) {

    x <- as.numeric(x)
    y <- as.numeric(y)
    ly <- as.numeric(ly[subscripts])
    uy <- as.numeric(uy[subscripts])
    panel.arrows(x, ly, x, uy, col = 'black',

                 length = 0.25, unit = "native",
                 angle = 90, code = 3)

    panel.xyplot(x, y, pch = pch, ...)
}

with(singer.ucl,

     xyplot(median ~ voice.part, groups=group1,
            ly = lower, uy = upper,
            prepanel = prepanel.ci,
            panel = function(x, y, ...) {
                panel.abline(v = unique(as.numeric(x)),
                             col = "grey")
                panel.superpose(x, y, ...)
            },
            panel.groups = panel.ci,
            pch = 16))

Let us know if anything is not obvious.

-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. Received on Sat Oct 14 08:08:39 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 13 Oct 2006 - 22:30:11 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.