[R] Putting splom in a function

Gabor Grothendieck ggrothendieck at gmail.com
Thu Feb 15 16:56:21 CET 2007


If you call splom with do.call then your solution should work:

   do.call("splom", list(~data[cols], groups = as.symbol(groups), data = data,
     panel = panel.superpose, col = colors))

or use as.name where as.symbol is which also works.

On 2/14/07, Roberto Perdisci <roberto.perdisci at gmail.com> wrote:
> 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