[R] persp(), scatterplot3d(), "..." argument
Robin Hankin
rksh at soc.soton.ac.uk
Tue Oct 26 12:28:08 CEST 2004
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.
(the odd argument jj.colour is there because persp() needs to
be called with col=NA).
--
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
SO14 3ZH
tel +44(0)23-8059-7743
initialDOTsurname at soc.soton.ac.uk (edit in obvious way; spam precaution)
More information about the R-help
mailing list