Last active
March 14, 2017 22:57
-
-
Save jasper1918/cc5551bb03c69c37c41536d8fa7fe978 to your computer and use it in GitHub Desktop.
mypca
This file contains 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
mypca<-function(x, mytitle="", ...) | |
{ | |
par(mfrow=c(1,1)) | |
this_pc <- prcomp(x, scale=FALSE) | |
this_pc_coord <- this_pc$x | |
pc1pct=round(summary(this_pc)$importance[2,1]*100,2) | |
pc2pct=round(summary(this_pc)$importance[2,2]*100,2) | |
par(mar = c(8, 5, 3, 8), xpd=T) | |
plot(this_pc_coord[,1], this_pc_coord[,2], pch = 19, cex=2, | |
xlab=paste0("PC1(",pc1pct,"%)"),ylab=paste0("PC2(",pc2pct,"%)"), bty="l", xpd=T, | |
main=mytitle) | |
abline(h=0, v=0, lty = 2, xpd=F, lwd=.1, col="gray70") | |
text(this_pc_coord[,1], this_pc_coord[,2], labels=rownames(this_pc_coord), | |
cex=1, pos = 4) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment