Created
April 10, 2012 20:05
-
-
Save bmpvieira/2354104 to your computer and use it in GitHub Desktop.
Short PCA example with FactoMineR and ggplot2 in R
This file contains hidden or 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
#Copyright (c) 2012 Bruno Vieira [http://bmpvieira.com] | |
#License: CC BY | |
#Short PCA example with FactoMineR and ggplot2 in R | |
library(FactoMineR) | |
library(ggplot2) | |
data = read.table("data.tsv", head=T, row.names=1) | |
pca = PCA(data[,2:ncol(data)], scale.unit=T, graph=F) | |
PC1 = pca$ind$coord[,1] | |
PC2 = pca$ind$coord[,2] | |
plotdata = data.frame(cbind(group=data[,1],PC1,PC2)) | |
plotdata$group = factor(plotdata$group) | |
plot = ggplot(plotdata, aes(PC1, PC2)) + | |
geom_text(aes(label=rownames(plotdata)), size=2.5, hjust=0.5, vjust=-0.5) + | |
geom_point(aes(colour=group)) | |
print(plot) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment