perfettiful
4/7/2016 - 1:17 AM

Sample code to plot PCs coefficients associated with variables in the dataset. See http://tgmstat.wordpress.com/2013/11/28/computing-and-vis

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")