Skip to content
Prev 177406 / 398506 Next

Color of points in a 3d plot of a PCA

On 4/17/2009 10:43 AM, Alejandro Gonz?lez wrote:
As long as the order of rows in the matrix is unchanged when you 
calculate the pc scores, you should be able to use a separate dataframe 
or vector to give information about each row, and to work out a colour 
for plotting it.

For example:


X <- matrix(rnorm(1000), 100, 10)
# Make up a fake population based on the first column
popn <- round(X[,1])
colour <- popn - min(popn) + 1
pc <- princomp(X)
library(rgl)
plot3d(pc$scores[,1:3], col=colour)

Duncan Murdoch