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? I would be grateful if anybody could help me. Kilian _________________________________________________________________ Die neue MSN Suche Toolbar mit Windows-Desktopsuche. Suchen Sie gleichzeitig im Web, Ihren E-Mails und auf Ihrem PC! Jetzt neu! http://desktop.msn.de/ Jetzt gratis downloaden!
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?Unfortunately, there is not the same level of control that is available for 2D plots, but you can "cheat" a bit in this case. For example, ... 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, 1)) 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") Paul -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/
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? >> PaulAnother 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")
Jose Claudio Faria
2006-Jul-26 11:10 UTC
[R] Axis Title in persp() Overlaps with Axis Labels
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 em terra.com.br jc_faria em uesc.br jc_faria em 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")