[R] ploting 2 variables in a lattice xyplot

Deepayan Sarkar deepayan at stat.wisc.edu
Tue Sep 9 19:58:32 CEST 2003


On Tuesday 09 September 2003 10:35 am, Douglas Bates wrote:
> Ernesto Jardim <ernesto at ipimar.pt> writes:
> > Hi,
> >
> > I want to plot 2 variables (confidence intervals) in a single xyplot. I
> > have a dataframe with variables Yup, Ylo, X and Z and I want to have a
> > xyplot with both variables ploted. I'm trying with
> >
> > xyplot(Yup~X|Z, panel=function(x){...})
> >
> > but this way I'm not able to pass variable Ylo into the function...
> >
> > How can I do this ?
>
> According to the "formula" description on the manual page for xyplot
> you can use
>
> xyplot(Ylo+Yup~X|Z, allow.multiple=TRUE)
>
> Did you try that?

Yes, this seems to work with the following panel function:

panel = function(x, y, groups, subscripts, ...) {
    groups <- as.numeric(groups)
    lsegments(x[groups[subscripts] == 1], y[ groups[subscripts] == 1],
              x[groups[subscripts] == 2], y[ groups[subscripts] == 2], ...)
}

Deepayan




More information about the R-help mailing list