[R] rgl: axis/viewport/box problems in persp3d()
murdoch.duncan at gmail.com
Fri Sep 9 12:41:31 CEST 2011
On 11-09-09 6:18 AM, Marius Hofert wrote:
> Dear expeRts,
> I am a new user of rgl, below is my first trial to plot a simple function in 3d.
> I managed to put the axes in the right locations, but:
> (1) The xlab, ylab, and zlab arguments are ignored; how can I put in axes labels?
Those are documented on the axes3d page, but are arguments to title3d,
not axes3d. So add title3d(xlab="x", etc.
> (2) Since I removed the axes in persp3d() the viewport is too small; is it possible
> to keep the size of the viewport?
You can manually adjust it to your taste, then write down the value of
par3d("zoom"). Later you can reproduce the resizing by calling
par3d(zoom= <saved value> ).
> (3) The box is not correctly drawn, there are two "holes", one in (0,0,1) and one
> in (1,1,0); how can I fix that?
That happens because OpenGL has a limit on the range of depths that can
be displayed, and the corners of the box have been adjusted to be too
close or far. This is arguably a bug in rgl, but it's sometimes a feature.
What I'd suggest is that you don't use rgl.viewpoint, you just manually
adjust the display as you like, without making it quite as extreme, then
record the values of par3d(c("userMatrix", "zoom", "FOV")); those
control the viewpoint.
> s<- seq(0, 1, length.out=21)
> M<- function(u) apply(u, 1, min)
> u<- s
> v<- s
> z<- outer(u, v, function(u,v) M(cbind(u,v)))
> persp3d(u, v, z, aspect="iso", front="line", lit=FALSE, axes=FALSE, xlab="",
> ylab="", zlab="")
> axes3d(edges=c('x--','y--','z+-'), xlab="x", ylab="y", zlab="z")
> R1<- rotationMatrix(-55*pi/180, 1,0,0)
> R3<- rotationMatrix(50*pi/180, 0,0,1)
> R<- R1 %*% R3
> rgl.viewpoint(interactive=TRUE, userMatrix=R) # rotate
> rgl.postscript("myplot.pdf", fmt="pdf")
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help