read.table("heptathlon.txt",header=TRUE)->hept # http://cran.r-project.org/web/packages/HSAUR/vignettes/Ch_principal_components_analysis.pdf library(HSAUR) plot(heptathlon) ht<-heptathlon[,-8] plot(ht) htpca<-princomp(ht,cor=TRUE) htpca2<-princomp(ht) summary(htpca) loadings(htpca) ?scale par(mfrow=c(1,2)) biplot(htpca) biplot(htpca2) #abline(h=0,v=0,lty=2) #ht2<-ht #ht2$hurdles<-max(ht2$hurdles)-ht2$hurdles #ht2$run200m<-max(ht2$run200m)-ht2$run200m #ht2$run800m<-max(ht2$run800m)-ht2$run800m #plot(ht2) #loadings(pc2<-princomp(ht2,cor=T)) #summary(pc2) #biplot(pc2) str(htpca) htpca$scores[,1] #par(mfrow=c(1,2)) #biplot(htpca) #biplot(pc2) #ht_pca <- prcomp(ht, scale=TRUE) #summary(ht_pca) a1<-htpca$loadings[,1] a1 a2<-htpca$loadings[,2] a2 plot(htpca$scores[,1],heptathlon$score,col=rainbow(25),pch=16) plot(htpca$scores[,2],heptathlon$score,col=rainbow(25),pch=16)