[R] rgl: plot3d and ellipse3d

Michael Friendly friendly at yorku.ca
Wed Sep 17 15:40:53 CEST 2008


Yihui Xie wrote:
> Hi Michael,
>
> You need to specify both 'box' and 'axes' to FALSE to avoid the box
> lines (if you don't specify the latter one, there will still be axes
> lines).
>
>
>   
Hi Yihui
I tried several variations, none of which would simply add the ellipse 
and nothing else to the original
plot of points:

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

# how to avoid the extra box?
# -- this doesn't remove the extra box, but keeps the points & axis labels
plot3d( ellipse3d(cov, centre=mu, level=0.68, box=FALSE), col="pink", 
alpha=0.2,  add = TRUE, axes=FALSE)

# -- this removes the original axes, the points & labels axes x, y, z
plot3d( ellipse3d(cov, centre=mu, level=0.68, box=FALSE, col="pink", 
alpha=0.2,  add = TRUE, axes=FALSE))

-Michael
>
> On Wed, Sep 17, 2008 at 8:34 PM, Michael Friendly <friendly at yorku.ca> wrote:
>   
>> 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?
>>     

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