Reputation: 5069
I have a correlation matrix, that looks like this:
A B C D E
A 1.00000000 0.08076432 -0.11462447 -0.10395283 -0.27033234
B 0.08076432 1.00000000 -0.05978118 -0.06478300 -0.11423989
C -0.11462447 -0.05978118 1.00000000 -0.03884304 -0.09946262
D -0.10395283 -0.06478300 -0.03884304 1.00000000 0.01411555
E -0.27033234 -0.11423989 -0.09946262 0.01411555 1.00000000
I am doing pca and plotting it (all in R):
PCA<-princomp(cor_matrix)
names(PCA)
PCA$sdev
plot(PCA$scores[,1:2])
Now, how can i get in the labels with different colors along with the legend.
Thank you
Upvotes: 0
Views: 7050
Reputation: 206566
You can do something like this
groups <- factor(rownames(PCA$scores))
plot(PCA$scores[,1:2], col=groups)
legend(0,0,groups, col=groups, pch=1)
text(PCA$scores[,1:2], labels=groups, pos=3)
Those are all base plotting functions. You may wish to tweak the default settings to make your plot look prettier. To do so, read the help pages for each of those functions.
Upvotes: 2