[R] adding text to persp

Sundar Dorai-Raj doraiss at auburn.edu
Thu Nov 8 15:20:05 CET 2001


> 
> On a related topic to this - can someone tell me how to 
> independently alter the fontsize and position of text on a 
> persp plot?? 
> I've tried using titles() and axes() but they seem to only 
> apply to the standard plot() and contour plots (contour() and 
> filled.contour(). 
> 

Here's the solution I came up with, though it's not general enough to
write into a function. It uses text() instead of axis() and title().

Sundar

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(mar=c(1,1,1,1))
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue",
           ltheta = 120, shade = 0.75, ticktype = "detailed",
           xlab = "", ylab = "", zlab = "")

u.x <- par("usr")[1:2]
u.y <- par("usr")[3:4]
text(x=u.x[1]+.94*diff(u.x),
     y=u.y[1]+.34*diff(u.y),
     labels=expression(theta),
     srt=45,cex=1.2)
text(x=u.x[1]+.21*diff(u.x),
     y=u.y[1]+.16*diff(u.y),
     labels=expression(gamma[r]),
     srt=-45,cex=1.2)
text(x=u.x[1]+.04*diff(u.x),
     y=u.y[1]+.60*diff(u.y),
     labels=expression(italic(f)[Theta](theta,gamma[r])),
     srt=100,cex=1.2)

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list