I am trying to make a reasonable looking PCA analysis, where not only data are projected in two axis, but also the loadings of the data are projected on top of the data.
Similar to the following figure by @amoeba, taken from this answer:
I am doing this in R and to visualize I use the ggplot command. But as soon as I plot the loading on top they look much smaller in the plot. I assume, I should scale the PCA's loading to make the arrows bigger, but I don't know how to do that.
res.pca <- prcomp(wine, scale = TRUE) # read Wine data and do PCA
loadings <- res.pca$rotation # PCA returns loadings (eigenvectors)
sdev <- res.pca$sdev # standard deviation
# make a data frame of PCs
my.df = data.frame(pc1 = res.pca$x[,1], # pc1
pc2 = res.pca$x[,2]) # pc2
# make a dataframe for the loadings arrows
arrow.df = data.frame(x1 = rep(0, length(loadings[,1])),
y1 = rep(0, length(loadings[,1])),
x2 = loadings[,1],
y2 = loadings[,2])
ggplot(my.df, aes(x = pc1, y = pc2)) + geom_point() + geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2),data = arrow.df)
Here is the result:
pca loadings eigenvectors
,biplot
. In particular, user @amoeba and myself were writing exactly on that topic several times. $\endgroup$