Skip to content

Instantly share code, notes, and snippets.

@benmarwick
Last active December 15, 2015 21:59
Show Gist options
  • Save benmarwick/5329763 to your computer and use it in GitHub Desktop.
Save benmarwick/5329763 to your computer and use it in GitHub Desktop.
Using R for three-dimensional plotting of the output of a PCA
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