Access to conditioning variables (lattice)
-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of Martin D. Lepage
Sent: Thursday, September 24, 2009 7:38 AM
To: r-help at r-project.org
Subject: [R] Access to conditioning variables (lattice)
[using R version 2.8.1 (2008-12-22)]
Hello,
I'm trying to access the conditioning variables of an xyplot within a
'panel' function but I have not been able to figure out how to do so.
Here is a simple example that describes what I wish to do (the problem
lies with the commented line):
dataset <- data.frame(x = c(1,2), y = c(4,5), Type =
factor(c("a","b")))
xyplot( y ~ x | Type, dataset,
panel = function(...) {
panel.xyplot(...)
# do_something_with(conditioning_variables[which.packet()])
})
The problem I am facing is that I do not know how to
generically access
the conditioning variables within the panel function. In this simple
case, I can achieve what I want to do with the following call :
do_something_with(Type[which.packet()])
If your panel function has an argument called 'subscripts' then
xyplot will pass it the row numbers of the data argument that
correspond this the current panel. E.g.,
> xyplot( y ~ x | Type, dataset,
+ panel = function(..., subscripts) {
+ panel.xyplot(...)
+ cat("subscripts=", deparse(subscripts), ":\n")
+ print(dataset[subscripts,])
+ })
subscripts= 1L :
x y Type
1 1 4 a
subscripts= 2L :
x y Type
2 2 5 b
You can use that information to add panel-specific information
to the plot.
Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com
but that requires the panel function call to have prior knowledge of the object used as the conditioning variable, which is not flexible enough for my needs. Thank you, Martin D. Lepage
______________________________________________ R-help at r-project.org 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.