Re: [R] question on rgl.surface

From: Duncan Murdoch <>
Date: Sat, 21 Jun 2008 21:38:04 -0400

On 21/06/2008 2:48 PM, Mark Kimpel wrote:
> I'd like to use rgl.surface (or some other function if more
> appropriate) to create a horizontal and vertical transparent grey
> slice (plane) running through both the x and y origins and extending
> across the z axis, i.e. the 3-d equivalent of the normal 2-d
> coordinate axes we are all familiar with. The examples for rgl.surface
> are a bit more complex than what I need and I am having trouble
> understanding them.
> Here is the code if I come up with, but which obviously doesn't work.
> require(rgl)
> set.seed(123)
> d3.mat <- matrix(runif(30, min = -5, max = 5), ncol = 3, nrow = 10)
> open3d()
> plot3d(x = d3.mat, type = "s", col = "blue", size = 0.33, xlab ="x",
> ylab = "y", zlab = "z")
> x <- 0
> y <- 0
> z <- matrix(c(floor(min(d3.mat[,1])),ceiling(max(d3.mat[,1])),floor(min(d3.mat[,3])),ceiling(max(d3.mat[,3]))),nrow
> = 2, ncol =2)
> rgl.surface(x, z, y, color="grey", back="lines")

You used open3d(), so you should use surface3d(), not rgl.surface(). The *3d functions interact with each other differently than the lower level rgl.* functions, and it's usually not a good idea to mix them.

You could get what you want with quads3d, by working out the corners of the rectangle you want:

quads3d(0, range(d3.mat[,2])[c(1:2,2:1)], range(d3.mat[,3])[c(1,1,2,2)], col="grey", alpha=0.3)

quads3d(range(d3.mat[,1])[c(1:2,2:1)], 0, range(d3.mat[,3])[c(1,1,2,2)], col="grey", alpha=0.3)

(This will look strange after your rgl.surface() call, but would otherwise be fine.)

There's also the grid3d() function if you want lines on the grids, e.g.

grid3d("x", at=list(x=0))
grid3d("y", at=list(y=0))

> What am I doing wrong?
> And, while I'm at it, there is another minor question I have, which is
> "how can I exaggerate the size difference in the spheres between front
> and back?"

You want to change your viewpoint so that the screen is displayed as if it is closer to you. The middle mouse button normally controls that, or you can increase the par3d("FOV") value from the default of 30.

Duncan Murdoch mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sun 22 Jun 2008 - 01:41:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 22 Jun 2008 - 03:30:55 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive