Re: [R] Axis Title in persp() Overlaps with Axis Labels

From: Jose Claudio Faria <joseclaudio.faria_at_terra.com.br>
Date: Wed 26 Jul 2006 - 21:10:36 EST


Dear Kilian,

Also give a looked at:
http://wiki.r-project.org/rwiki/doku.php?id=graph_gallery:new-graphics

You will see a new and very flexible function to 3D plot.

Regards,
__
Jose Claudio Faria
Brasil/Bahia/Ilheus/UESC/DCET
Estatística Experimental/Prof. Adjunto
mails: joseclaudio.faria@terra.com.br

        jc_faria@uesc.br
        jc_faria@uol.com.br

Paul Murrell <p.murrell <at> auckland.ac.nz> writes:

>
> Hi
>
> Kilian Plank wrote:
> > Good morning,
> >
> > in a 3D plot based on persp() the axis title (of dimension z)
overlaps with
> > the axis labels.
> > How can the distance (between axis labels and axis title) be increased?
>

> Paul

   Another way to do it: get the perspective matrix back from persp() and use trans3d() to redo essentially the same calculations that persp() does to decide where to put the label:

x <- seq(-10, 10, length= 30)
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(mfrow=c(2, 2))
persp(x, y, z, theta = 30, phi = 30, expand = 0.5,

       col = "lightblue", ticktype="detailed")

persp(x, y, z, theta = 30, phi = 30, expand = 0.5,

       col = "lightblue", ticktype="detailed",
       zlab="\n\n\n\nz")

p1 <- persp(x, y, z, theta = 30, phi = 30, expand = 0.5,
       col = "lightblue", ticktype="detailed",zlab="")

ranges <- t(sapply(list(x,y,z),range))
means <- rowMeans(ranges)

## label offset distance, as a fraction of the plot width labelspace <- 0.12 ## tweak this until you like the result

xpos <- min(x)-(diff(range(x)))*labelspace
ypos <- min(y)-(diff(range(y)))*labelspace
labelbot3d <- c(xpos,ypos,min(z))
labeltop3d <- c(xpos,ypos,max(z))
labelmid3d <- c(xpos,ypos,mean(range(z)))

trans3dfun <- function(v) { trans3d(v[1],v[2],v[3],p1) }
labelbot2d <- trans3dfun(labelbot3d)

labelmid2d <- trans3dfun(labelmid3d)
labeltop2d <- trans3dfun(labeltop3d)
labelang <-
180/pi*atan2(labeltop2d$y-labelbot2d$y,labeltop2d$x-labelbot2d$x) par(xpd=NA,srt=labelang) ## disable clipping and set string rotation text(labelmid2d[1]$x,labelmid2d$y,"z label")

R-help@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. Received on Wed Jul 26 21:21:28 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 26 Jul 2006 - 23:03:45 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.