Created
November 28, 2013 09:45
-
-
Save thigm85/7689508 to your computer and use it in GitHub Desktop.
Sample code to plot PCs coefficients associated with variables in the dataset. See http://tgmstat.wordpress.com/2013/11/28/computing-and-visualizing-pca-in-r/ for more info.
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
require(ggplot2) | |
theta <- seq(0,2*pi,length.out = 100) | |
circle <- data.frame(x = cos(theta), y = sin(theta)) | |
p <- ggplot(circle,aes(x,y)) + geom_path() | |
loadings <- data.frame(ir.pca$rotation, | |
.names = row.names(ir.pca$rotation)) | |
p + geom_text(data=loadings, | |
mapping=aes(x = PC1, y = PC2, label = .names, colour = .names)) + | |
coord_fixed(ratio=1) + | |
labs(x = "PC1", y = "PC2") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I am using this code. How can I change the labels to a smaller size? I have more variables, some labels are overlapping. Thank you.