Re: [R] indexing within panels in xyplot

From: Sebastian Luque <spluque_at_gmail.com>
Date: Wed 22 Feb 2006 - 03:48:05 EST

"Deepayan Sarkar" <deepayan.sarkar@gmail.com> wrote:

[...]

> Well, there are exceptions to this rule, but generally x and y, when
> they are passed on to the panel function, are _already_ subsetted, so
> x[subscripts] makes absolutely no sense. Note how your panel function
> calls

> panel.xyplot(x, y, ...)

> without referring to subscripts at all. The subscripts argument is
> there for other variables (e.g. if you were drawing confidence
> intervals, and had a separate vector in your data specifying the
> interval lengths). In your case, there are no other variables
> involved, so just get rid of the subscripts.

Thanks Deepayan, I was indeed quite confused about this.

I realized I needed to limit the fitted line to the range of x values the line is fit to, so I changed to panel.curve:

---<---------------cut here---------------start-------------->--- xyplot(y ~ x | facA, groups = facB, data = toydf,

       panel.groups = function(x, y, ...) {
         panel.xyplot(x, y, ...)
         lindx <- which(y == max(y, na.rm = TRUE))
         xleft <- mean(x[lindx], na.rm = TRUE)
         fit <- lm(y[x >= xleft] ~ x[x >= xleft])
         panel.curve(coef(fit)[1] + (coef(fit)[2] * x),
                     xleft, max(x, na.rm = TRUE))
       })

---<---------------cut here---------------end---------------->---

but can't find a way to color the line for each group differently. I tried passing a length-2 vector as a 'col' argument to panel.curve. Unfortunately it's only picking the first, so that both lines get colored the same. I'm not sure, but it seems as if I need to use 'panel.superpose' directly to do this, as the help page suggests the above would work?

Cheers,

-- 
Sebastian P. Luque

______________________________________________
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
Received on Wed Feb 22 04:20:01 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:38 EST