[R] Access to conditioning values in "xyplot"
Deepayan Sarkar
deepayan.sarkar at gmail.com
Thu Jul 13 18:14:01 CEST 2006
On 7/13/06, Jean-Marc Ottorini <ottorini at nancy.inra.fr> wrote:
>
> Dear R-help subscribers,
>
> Many thanks for all the answers I received either by mail or through
> the list, and that were most helpful.
>
> For the sake of the list records, I wanted to post the solution, I
> eventually could obtain, to the problem I have submitted.
>
> I am summarizing the question here. It was how to use the panel
> function "panel.curve" when the expression used in this function to to
> add a fitted line to the points in each panel depends not only on x,
> but also on the value of the conditioning variable for the considered
> panel.
>
> This solution is based on hints given to me by Deepayan Sarkar, it
> relies on the use of "packet.number" and "panel.number":
>
> xyplot(n ~ cg | di, data = myData,
> scale = list(y = "free", x = "free"),
> groups = bloc,
> as.table = T,
> xlab = "Cg",
> ylab = "N / ha",
> panel = function(x, y, subscripts, groups, packet.number = di,
> panel.number, ...) {
> panel.grid(h = -1, v = -1, col = "grey", lwd = 1, lty = 2)
> panel.curve(expr =
> f.fit(unique(rev(packet.number))[panel.number], a, b, a1, b1, x),
> n = 50, curve.type = "l", col = "lightblue", ...)
> panel.superpose(x, y, pch = c(1, 2), col =
> c("deeppink","blue"),
> panel.groups = "panel.xyplot", subscripts,
> groups)
> },
>
> key = list( space = "top", transparent = TRUE, columns = 2,
> points = list( pch = c(1, 2), col = c("deeppink", "blue") ),
> text = list( c("bloc 3", "bloc 4"))),
> )
>
> Some comments:
>
> - the arguments "packet.number = di, panel.number" must appear on the
> panel function prototype
> - a, b, a1, b1 are parameters set to a certain value before calling
> "xyplot"
> - "unique" is needed to reduce to 1 the multiple instances of the value
> of the conditioning variable di for a given panel (one for each point)
> - I was surprised by the need to use "rev" in order for the interval of
> the values to draw the curve f.fit to correspond to the right panel.
>
> Any further comment would be welcome
It's difficult to do so without a reproducible example.
Deepayan
More information about the R-help
mailing list