Travels in 3D space
description
Transcript of Travels in 3D space
![Page 1: Travels in 3D space](https://reader034.fdocuments.net/reader034/viewer/2022051623/568159a6550346895dc707c6/html5/thumbnails/1.jpg)
Travels in 3D space
Data ellipsoids, biplots, and rgl movies
SCS Seminar, Oct., 2008
![Page 2: Travels in 3D space](https://reader034.fdocuments.net/reader034/viewer/2022051623/568159a6550346895dc707c6/html5/thumbnails/2.jpg)
Prelude
• Multivariate data often needs > 2D Usually reduced to multiple 2D views
• Static 3D visualization often Badly rendered Lacks control of perspective Lacks direct manipulation of viewpoint
• Dynamic 3D visualization ggobi / rggobi – powerful dynamic graphics, but
crummy rendering rgl – beautiful rendering, good interactive control of
perspective, viewpoint, etc., weak 3D “tours”• Goal: Explore 3D vis & animation with rgl
![Page 3: Travels in 3D space](https://reader034.fdocuments.net/reader034/viewer/2022051623/568159a6550346895dc707c6/html5/thumbnails/3.jpg)
Iris data: rgl:::plot3d()
data(iris); library(rgl)col <-c("blue", "green", "red")[iris$Species]plot3d(iris, type="s", size=0.4, col=col, cex=2, box=FALSE, aspect="iso")
![Page 4: Travels in 3D space](https://reader034.fdocuments.net/reader034/viewer/2022051623/568159a6550346895dc707c6/html5/thumbnails/4.jpg)
Add data ellipse
cov <- cov(iris); mu <- mean(iris)plot3d( ellipse3d(cov, centre=mu, level=0.68), col="gray", alpha=0.2, add = TRUE)
![Page 5: Travels in 3D space](https://reader034.fdocuments.net/reader034/viewer/2022051623/568159a6550346895dc707c6/html5/thumbnails/5.jpg)
Add PC axes
source("c:/R/functions/ellipse3d.axes.R")axes <- ellipse3d.axes(cov, centre=mu, level=0.72, labels=TRUE)M1 <- par3d("userMatrix")
![Page 6: Travels in 3D space](https://reader034.fdocuments.net/reader034/viewer/2022051623/568159a6550346895dc707c6/html5/thumbnails/6.jpg)
Rotate to show PC1 & PC2: Biplot view
# hand rotate / zoom, then save current positionM2 <- par3d("userMatrix")
![Page 7: Travels in 3D space](https://reader034.fdocuments.net/reader034/viewer/2022051623/568159a6550346895dc707c6/html5/thumbnails/7.jpg)
Rotate to show PC1 & PC3
M3 <- par3d("userMatrix")
![Page 8: Travels in 3D space](https://reader034.fdocuments.net/reader034/viewer/2022051623/568159a6550346895dc707c6/html5/thumbnails/8.jpg)
Rotate to show PC2 & PC3
M4 <- par3d("userMatrix")
![Page 9: Travels in 3D space](https://reader034.fdocuments.net/reader034/viewer/2022051623/568159a6550346895dc707c6/html5/thumbnails/9.jpg)
Biplot movie: rotation to PC coordinates
interp <-par3dinterp( userMatrix=list(M1, M2), extrapolate="constant", method="linear")movie3d(interp, duration=4, fps=8, movie="biplot3d-iris")
![Page 10: Travels in 3D space](https://reader034.fdocuments.net/reader034/viewer/2022051623/568159a6550346895dc707c6/html5/thumbnails/10.jpg)
Grand tour: Interpolation thru multiple views
interp3 <-par3dinterp(userMatrix=list(M1, M2, M3, M4, M3, M2, M1), extrapolate="constant", method="linear" )movie3d(interp3, duration=6, fps=8, movie="biplot3d-iris3", dir="../anim")
![Page 11: Travels in 3D space](https://reader034.fdocuments.net/reader034/viewer/2022051623/568159a6550346895dc707c6/html5/thumbnails/11.jpg)
View in PCA space: bpca package
library(bpca)col <-c("blue","green","red")[iris$Species] plot(bpca(iris[-5], method='hj', lambda.end=3), rgl.use=TRUE, obj.cex=.8, obj.col=col, simple.axes=FALSE, box=TRUE)
movie3d(spin3d(), movie="biplot3d-bpca“)
movie3d requires ImageMagik:
http://www.imagemagik.org
![Page 12: Travels in 3D space](https://reader034.fdocuments.net/reader034/viewer/2022051623/568159a6550346895dc707c6/html5/thumbnails/12.jpg)
movie3d details
• rgl can only write .png files. movie3d() just writes a lot of them• Default: writes duration x fps .png files to the current or dir=
directory Need to figure out how time relates to angular rotation E.g., spin3d() uses rpm=5, so need duration=12 to get 360o
• Calls: convert –delay 1x{fps} movie*.png movie.gif, producing an animated .gif image. Animated .gif can be viewed as an animation in most browsers (e.g.,
Firefox) and Powerpoint, but will not animate in many image viewers (IM display, …) or in .pdf files created from PPT (like this one).
Once the frames have been created, you can run convert in a DOS shell with other parameters, or create other movie formats, e.g., mpeg, pdf, ...
• LaTeX beamer: I’ve discovered how to run movie3d .gif animations from a beamer .pdf file. The room left on this slide is too small to say how.