# [R] Graphical parameters in perspective plot

Paul Murrell paul at stat.auckland.ac.nz
Thu Feb 22 22:19:51 CET 2001

Hi

> I've a problem for setting graphical parameters in perspective plot
> (function persp).
> I wonder if it's possible to add some text (function text) on an
> existing persp plot USING the axis coordinates.
> In fact I want to add some text on a persp plot according to x
> coordinates.
> I've tried to use text(xcoord,ycoord, label="toto") but the toto text
> doesn't appear at (xcoord, ycoord) following the xy axis.
> Maybe function text is not accurate for 3D plots ?

Unfortunately, all of the annotation functions -- text(), points(), lines(),
... -- only work in 2D.
In S-Plus, persp() returns a value that can be used to transform 3D
locations to 2D, but this sort of thing is not (yet) available in R.  If the
annotations you have in mind are _very_ simple then it might be enough to
make use of the value of par("usr").  For example, to stick a big ugly label
right in the middle of the persp plot you could do something like ...

# one of the persp() examples
x <- seq(-10, 10, length=50)
y <- x
f <- function(x,y)
{
r <- sqrt(x^2+y^2)
10 * sin(r)/r
}
z <- outer(x, y, f)
z[is.na(z)] <- 1
par(bg = "white")
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue",
xlab = "X", ylab = "Y", zlab = "Z")

# a very basic annotation
text(mean(par("usr")[1:2]), mean(par("usr")[3:4]), "My Perspective Plot
!!", col="red", cex=3)

Again depending on what you want to do, Uwe Ligges' scatterplot3d package
might be useful because it appears to provide 3D to 2D transformations, .

> By the way, is it possible to modify the ticks length (separately for
> each axis) since the arguments tcl and tck seem to be non efficient, and
> to modify the box draw type to have a dotted box instead of a lined box
> (the argument bty is non efficient).

persp() allows normal par() arguments to be passed to it, but unfortunately
it ignores virtually all of them.  This will hopefully be fixed in the
future.

Paul

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._