[R] rgl: plot3d and ellipse3d

Michael Friendly friendly at yorku.ca
Wed Sep 17 14:34:41 CEST 2008


Hi
I'm trying to make a 3d plot showing a point cloud, the corresponding 
data ellipse
and the principal axes of the ellipse as vectors.

library(rgl)
data(trees)
cov <- cov(trees)
mu <- mean(trees)

plot3d(trees, type="s", size=0.5, col="blue", cex=2)

In this step, an extra box is added.  I've tried using box=FALSE, but it 
has no effect.
# how to avoid the extra box?
plot3d( ellipse3d(cov, centre=mu, level=0.68), col="pink", alpha=0.2,  
add = TRUE)

Here's what I've tried to plot the principal axes in variable space, 
using the result of prcomp().
But I've got something wrong, because, although they are at right 
angles, they don't
align with the ellipse.

PC <- princomp(trees)
sdev <- PC$sdev         # component standard deviations
sd <- sqrt(diag(cov))   # variable standard deviations

# vectors in variable space of principal components
vec <- matrix(mu,3,3, byrow=TRUE) + diag(sd) %*% PC$loadings

for (j in 1:3) {
   mat <- rbind(mu, vec[j,])
   segments3d(mat, col="red")
}

Can someone help?

thanks,
-Michael


-- 
Michael Friendly     Email: friendly AT yorku DOT ca 
Professor, Psychology Dept.
York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street    http://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT  M3J 1P3 CANADA



More information about the R-help mailing list