[R] xyplot: Combining 'subscripts' and 'allow.multiple=T'

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Fri Apr 20 20:45:06 CEST 2007


Deepayan Sarkar said the following on 4/20/2007 11:42 AM:
> On 4/20/07, Sundar Dorai-Raj <sundar.dorai-raj at pdf.com> wrote:
>>
>>
>> Søren Højsgaard said the following on 4/20/2007 3:57 AM:
>> > Dear all, Consider this plot
>> >
>> > xyplot(Sepal.Length + Sepal.Width ~ Petal.Length | Species,
>> >        data = iris, allow.multiple=T,  outer=F,
>> >        panel = function(x,y,...) {
>> >             panel.xyplot(x,y,...)
>> >        }
>> > )
>> >
>> > I want to *add* some things to each panel and what I want to add 
>> involves using the data for each panel, so I try to take this subset 
>> of data out with subscripts:
>> >
>> > xyplot(Sepal.Length + Sepal.Width ~ Petal.Length | Species,
>> >        data = iris, allow.multiple=T, outer=F,
>> >        panel = function(x,y,subscripts,...) {
>> >             panel.xyplot(x,y,...)
>> >             subiris <- iris[subscripts,] # Something using this ...
>> >        }
>> > )
>> >
>> > and then I get
>> > Error in NextMethod("[") : argument "subscripts" is missing, with no 
>> default
> 
> Interesting. I get
> 
> Error in panel.superpose(x, y, type = type, groups = groups, pch = pch,  :
>        argument "subscripts" is missing, with no default
> 
> which is somewhat more informative.

Hi, Deepayan,

Neither Søren nor I mentioned sessionInfo, which may be the reason our 
error messages differ from yours:

 > sessionInfo()
R version 2.4.1 (2006-12-18)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
States.1252;LC_MONETARY=English_United 
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] "grid"      "stats"     "graphics"  "grDevices" "utils"     "datasets"
[7] "methods"   "base"

other attached packages:
   lattice
"0.14-17"

--sundar

> 
>> > Does anyone know how to obtain this??
>> >
>> > By the way: The doc on xyplot says:  "The value of subscripts 
>> becomes slightly more complicated when allow.multiple is in effect. 
>> Details can be found in the source code of the function 
>> latticeParseFormula.". Sure.
>> >
> 
> Maybe a better thing to say would be:
> 
>    "The documented value of 'subscripts' does not hold when
>     using an extended formula (with terms separated by '+')."
> 
> which while entirely useless, is completely accurate and at least
> wouldn't give you anything to complain about. Would you prefer that?
> 
> In any case, you can always do something like
> 
> panel = function(x, y, subscripts, ...) {
>    print(subscripts) ## debug
> },
> 
> R is a programming language after all, and if you are not prepared to
> use it as such, may be you shouldn't be writing complicated panel
> functions.
> 
> -Deepayan
> 
>> > Best regards
>> > Søren
>> >
>> >       [[alternative HTML version deleted]]
>> >
>> >
>> >
>> > 
>> ------------------------------------------------------------------------
>> >
>> > ______________________________________________
>> > R-help at 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.
>>
>>
>> Hi, Søren,
>>
>> Since you add "subscripts" to your panel arguments, you now need to
>> explicitly pass it on to panel.xyplot. Try:
>>
>>   xyplot(Sepal.Length + Sepal.Width ~ Petal.Length | Species,
>>         data = iris, allow.multiple=T, outer=F,
>>         panel = function(x,y,subscripts,...) {
>>              panel.xyplot(x,y,subscripts=subscripts,...)
>>              subiris <- iris[subscripts,] # Something using this ...
>> })
>>
>> HTH,
>>
>> --sundar
>>
>> ______________________________________________
>> R-help at 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.
>>



More information about the R-help mailing list