[R] Using axis limits with plot3D

Karline Soetaert Karline.Soetaert at nioz.nl
Thu Aug 7 12:15:52 CEST 2014


Hi Scott,

The trick is to postpone plotting (plot = FALSE) and then do plotdev() with the required limits:

library(plot3D)
x <- z <- seq(-4, 4, by=0.2)
y <- seq(-6, 6, by=0.2)
M <- mesh(x,y,z)
R <- with(M, sqrt(x^2 + y^2 +z^2))
p <- sin(2*R)/(R+1e-3)
x.limits <- c(-2, 2)
y.limits <- c(-2, 2)
slice3D(x,y,z, colvar=p, xs=0, ys=c(0, 4), zs=NULL, scale=F, ticktype="detailed", plot = FALSE) 

plotdev(xlim=x.limits, ylim=y.limits)


This should work.

Karline

Message: 25
Date: Wed, 6 Aug 2014 23:21:04 +0000
From: "Waichler, Scott R" <Scott.Waichler at pnnl.gov>
To: "R. Help" <r-help at r-project.org>
Cc: "karline.soetaert at nioz.nl" <karline.soetaert at nioz.nl>
Subject: [R] Using axis limits with plot3D
Message-ID:
	<074C83DAD4825242A20B2D83FDBCB888765969 at EX10MBOX03.pnnl.gov>
Content-Type: text/plain; charset="us-ascii"

I would like to use the functions in the plot3D package but I am having trouble getting the axis limits to work correctly.  The slices plotted by the code below go beyond the bounds of the persp box and obscure the axis information.  How can I show just the part of the domain within x.limits and y.limits?

library(plot3D)
x <- z <- seq(-4, 4, by=0.2)
y <- seq(-6, 6, by=0.2)
M <- mesh(x,y,z)
R <- with(M, sqrt(x^2 + y^2 +z^2))
p <- sin(2*R)/(R+1e-3)
x.limits <- c(-2, 2)
y.limits <- c(-2, 2)
slice3D(x,y,z, colvar=p, xs=0, ys=c(0, 4), zs=NULL, xlim=x.limits, ylim=y.limits, scale=F, ticktype="detailed")

Thanks,
Scott Waichler
Pacific Northwest National Laboratory
Richland, WA, USA




More information about the R-help mailing list