[R] persp(), scatterplot3d(), "..." argument

Uwe Ligges ligges at statistik.uni-dortmund.de
Wed Oct 27 09:04:44 CEST 2004


Robin Hankin wrote:

> 
> Hello list.
> 
> I very often need 3d scatterplots, and use scatterplot3D quite a lot.
> I am trying to modify persp() to plot scatterplots, and make use of
> the theta and phi arguments that persp() offers.  I am having some
> difficulty passing the correct arguments to persp().
> 
> Here is my function so far.  Much of it is copied from the persp() manpage.
> 
> 
> 
> points3d <- function(x,y,z, jj.colour="black", ...){
>   if(is.matrix(x)){
>     z <- x[,3]
>     y <- x[,2]
>     x <- x[,1]
>   }
>     z.grid <- matrix(range(z),2,2)
>     persp(range(x), range(y),    z.grid,
>     col = NA,border=NA, ...) -> res
> 
> 
>     trans3d <- function(x,y,z, pmat) {
>        tr <- cbind(x,y,z,1) %*% pmat
>        list(x = tr[,1]/tr[,4], y= tr[,2]/tr[,4])
>      }
> 
>   points(trans3d(x,y,z,pm=res), col=jj.colour, ...)
> }
> 
> 
> 
> With this, things like
> 
>    O <- matrix(rnorm(60),20,3)
>    points3d(O,jj.colour="red",pch=16,theta=30,phi=40)
> 
> work as expected, but all extra arguments are passed to persp() _and_
> lines() and this gives warnings.
> 
> 
> QUESTION:
> 
> What is best practice to handle this sort of problem?  Should I ignore
> the warnings() that this approach gives?  I can suppress them with
> options(warn= -Inf), but is this a good idea?  I've read section 10.4
> of AITR.

Many of us have thought about this problem.
I'd suggest to introduce frequently used arguments to your meta-function 
(such as main, xlab, ylab, ...), but ignore warnings (note: warnings, 
not errors) if less frequently arguments are passed through "...".

Alternatively, you can exclude "..." from lines() or points() and 
specify a list of arguments to be passed to that call.

Uwe Ligges



> (the odd argument jj.colour is there because persp() needs to
> be called with col=NA).




More information about the R-help mailing list