Skip to content
Prev 281071 / 398503 Next

3d plotting alternatives. I like persp, but regret the lack of plotmath.

On 11-12-29 1:01 PM, Paul Johnson wrote:
It doesn't get nicely rotated like the default labels and it requires 
some manual work, but you can get labels on there.  For example, 
run(example(persp)) to create x, y, z values.  Then to display an 
expression for the z label:

M <- persp(x,y,z, zlab="", col="green", theta=-30, phi=30)
p <- trans3d(min(extendrange(x, f=0.1)), max(extendrange(y, f=0.1)), 
mean(range(z)), M)
text(x=p$x, y=p$y, label=expression(x*y^2), xpd=NA)
But you can't do plotmath, and that's unlikely to change for a while. 
Eventually it might, but it's a lot of work.
You need to set your window as large as you possibly can, because the 
png is just a bitmap copy.  They are easier to put into Sweave documents 
as of R 2.14.0, just do something like

<<fig=TRUE, pdf=FALSE, grdevice=rgl.Sweave>>=

Setting windowRect to a large value using par3d() or by setting it in 
r3dDefaults before this chunk will make the bitmap quality much better. 
  Or you can try for pdf or eps output, but those tend not to work so well.
I doubt if it is impossible, it's just not going to be easy, because 
persp is mainly written in C, and is a fairly big piece of code.  But go 
ahead and do it (or hire someone to do it).

Duncan Murdoch