[R] OT: 3d surfaces with transparency
Ben Bolker
bolker at ufl.edu
Sat Dec 8 23:55:19 CET 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Deepayan Sarkar wrote:
> On 12/8/07, Ben Bolker <bolker at ufl.edu> wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>>
>> I would be grateful if anyone had suggestions
>> about software that could (1) create 3D surface
>> plots, (2) handle transparency/alpha blending,
>> (3) generate output in some vector graphics format
>> that preserved the transparency. I could also
>> live with a combination of two programs, one
>> to generate the basic figure and another to
>> modify the output surface to a transparent
>> color (but preserving vector-ness).
>>
[snip]
>> Any ideas???
>
> You could consider wireframe from lattice, but this has many caveats.
> For an example, see
>
> http://dsarkar.fhcrc.org/lattice/book/figures.html?chapter=06;figure=06_18;theme=stdColor;code=right
>
> For that matter, whats wrong with persp?
>
> -Deepayan
I hadn't thought about the fact that transparency is easier
than it used to be (esp. with cairo device/PDF).
OK, next question: is there an easier way than the following
to create a 3D perspective plot with reference grids on some faces?
I can pull the 3D grid code out of the rgl or scatterplot3d
packages and reimplement it here, I guess ... another way to
hack this might (?) be to play with tick lengths?
library(cairoDevice)
xgrid = seq(0,1,by=0.1)
ygrid = seq(0,1,by=0.1)
zgrid = seq(0,200,by=20)
zmin = min(zgrid)
zmax = max(zgrid)
ymin = min(ygrid)
ymax = max(ygrid)
xmin = min(xgrid)
xmax = max(xgrid)
p1 = persp(0:1,0:1,matrix(0,ncol=2,nrow=2),axes=FALSE,
xlab="",ylab="",zlab="",zlim=c(0,200))
invisible(lapply(xgrid,
function(x) {
t1 = trans3d(x,ymin,zmin,p1)
t2 = trans3d(x,ymax,zmin,p1)
segments(t1$x,t1$y,t2$x,t2$y,col="gray")
}))
invisible(lapply(ygrid,
function(y) {
t1 = trans3d(xmin,y,zmin,p1)
t2 = trans3d(xmax,y,zmin,p1)
segments(t1$x,t1$y,t2$x,t2$y,col="gray")
}))
invisible(lapply(xgrid,
function(x) {
t1 = trans3d(x,ymax,zmin,p1)
t2 = trans3d(x,ymax,zmax,p1)
segments(t1$x,t1$y,t2$x,t2$y,col="gray")
}))
invisible(lapply(zgrid,
function(z) {
t1 = trans3d(xmin,ymax,z,p1)
t2 = trans3d(xmax,ymax,z,p1)
segments(t1$x,t1$y,t2$x,t2$y,col="gray")
}))
par(new=TRUE)
p2 = persp(volcano,
col=rgb(1,0,0,0.5),border=NA)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFHWyDXc5UpGjwzenMRAvYVAJ9NTAjJ6wiTJlaFl2ewj74KXtruBwCgldTe
FufIEDizL9FA7Uk8LG8e/tY=
=HiWO
-----END PGP SIGNATURE-----
More information about the R-help
mailing list