Skip to content

Instantly share code, notes, and snippets.

@thigm85
Created November 28, 2013 09:45
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save thigm85/7689508 to your computer and use it in GitHub Desktop.
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.
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")
@berylia
Copy link

berylia commented Mar 9, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment