Last active
December 15, 2015 21:59
-
-
Save benmarwick/5329763 to your computer and use it in GitHub Desktop.
Using R for three-dimensional plotting of the output of a PCA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pc <- prcomp(~ . - Species, data = iris, scale = TRUE) | |
library(rgl) | |
plot3d(pc$x[,1:3], xlab="Component 1", ylab="Component 2", zlab="Component 3", type="n", box=F, axes=T) | |
decorate3d(xlab = "x", ylab = "y", zlab = "z", | |
box = TRUE, axes = TRUE, main = NULL, sub = NULL, | |
top = TRUE, aspect = FALSE, expand = 1.03) | |
spheres3d(pc$x[,1:3], radius=0.1, col=rep(c("red","green","black"), each = 50)) | |
grid3d(c("x", "y+", "z")) | |
text3d(pc$x[,1:3], text=rownames(pc$x), adj=1.3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment