[R] Rgl and plotmath symbols (via sprites): a trial

Marius Hofert m_hofert at web.de
Fri Sep 9 17:10:53 CEST 2011

Dear all,

Below is some code where I try to get plotmath symbols in an rgl plot. Duncan
Murdoch kindly suggested to use a "sprite" for this. As you can see, on can get
it to work, but my knowledge about grid and rgl is too limited to perfectly 
solve the problem. 
1) As you can see (please rotate the plot a little bit so that (0,0,0) is "in front"), 
the quality of the .png seems poor. Can this be improved?
2) When I print the file to a .pdf, the label is just a black square... I assume
one then has to print to png again... hmmm... not perfect.
3) Some parts of the z-axis are covered by the label. How can this be fixed?
The problem seems to be that sprites have a radius. Specifying a rectangle would
be better here, but I am not sure how this works (or even if it does). 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: plot.pdf
Type: application/pdf
Size: 76481 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110909/cee818d1/attachment.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screenshot.png
Type: image/png
Size: 34387 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110909/cee818d1/attachment.png>
-------------- next part --------------


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)))

## create z-axis label
png("zlabel.png", bg="transparent", width=70, height=70)

## plot
persp3d(u, v, z, aspect="iso", front="line", lit=FALSE, axes=FALSE, xlab="", 
        ylab="", zlab="") 
sprites3d(1,-0.4,0.65, radius=0.5, lit=FALSE, textype="alpha", texture="zlabel.png")
rgl.postscript("W.pdf", fmt="pdf") # print to file

# par3d(c("userMatrix", "zoom", "FOV")):
# $userMatrix
#            [,1]       [,2]       [,3] [,4]
# [1,]  0.7262191 -0.6867201 0.03195775    0
# [2,]  0.2750087  0.3328032 0.90200466    0
# [3,] -0.6300603 -0.6462642 0.43054202    0
# [4,]  0.0000000  0.0000000 0.00000000    1
# $zoom
# [1] 1
# $FOV
# [1] 30

More information about the R-help mailing list