[R] Putting splom in a function
Bert Gunter
gunter.berton at gene.com
Wed Feb 14 23:40:43 CET 2007
Roberto:
You need to do what ?xyplot says. as.symbol(groups) is not a variable and is
certainly not subsettable. If you have a variable named "groups" in your
data.frame , then ... groups = groups gives the grouping according to the
levels of that variable. If you do not, then it may be picking up a variable
named "groups" from somewhere else, probably your global workspace, which
may be producihg your unexpected results. Or perhaps there is a variable
named "groups" in you data frame which is not what you think it is. Have you
checked?
In any case, please examine or run the examples in ?xyplot, especially those
that use the group = argument.
One note: I do grant you that the phrase "variable or expression" may be
confusing in this context. But do note that ?as.expression explicitly says:
" 'Expression' here is not being used in its colloquial sense, that of
mathematical expressions. Those are calls (see call) in R, and an R
expression vector is a list of calls etc, typically as returned by parse."
What is meant by the phrase in the xyplot help is "expression" in its
colloquial sense of a math (or more generally, any R) expression, not a
formal expression object, which is what the cast as.expression() gives.
Bert Gunter
Genentech Nonclinical Statistics
South San Francisco, CA 94404
650-467-7374
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Roberto Perdisci
Sent: Wednesday, February 14, 2007 1:05 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Putting splom in a function
Hello R list,
I have a little problem with splom. I'd like to wrap it in a
function, for example:
multi.scatterplot <- function(data,groups,cols,colors) {
splom(~data[,cols], groups = as.symbol(groups), data = data, panel
= panel.superpose, col=colors)
}
and then call it like in
multi.scatterplot(iris,"Species",1:4,c("green","blue","red"))
but the problem is:
Error in form$groups[form$subscr] : object is not subsettable
if I use
groups = groups
instead of
groups = as.symbol(groups)
shomthing is plotted, but not the correct scatterplot.
I think the problem is that I don't cast the 'groups' variable to the
correct type. Besides as.symbol() I tried also as.expression(),
because ?xyplot says "groups: a variable or expression to be evaluated
in the data frame specified by 'data'".
What is the correct type? What as.* should I use?
thank you,
regards,
Roberto
______________________________________________
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