rpca

How to visualize PCA variable loadings as barplot?


I am currently using R Studio and tackling a task that'd require me to create a visual that allows me to examine the loadings from PC1 and PC2 from a PCA and identify which loadings (disregarding the sign) are greater than 0.3.

I am aware that this information is readily and simply available by looking at the console output for:

round(pca$rotation, 3)

Where I am rounding to 3 d.p. the Loadings/coefficients for the PCs found in a PCA called "pca"

However, for the sake of my task, I'd like to be able to reinforce these numbers with a simple visual like a barplot or something that's doable using tidyverse packages.


Solution

  • Just use barplot.

    barplot(pcar[, c('PC1', 'PC2')], beside=TRUE, col=seq_len(ncol(pcar)) + 1,
            legend=rownames(pcar), args.legend=list(x='top'))
    abline(h=0.3, col='red', lty=2)
    

    enter image description here


    Data:

    pcar <- prcomp(USArrests)$rotation