Hi everyone,

I used the factoextra package to make the biplot with top=20 contributed vars.
The code is:

**fviz_pca_biplot(pca_result1, title = "", col.var = "steelblue", select.var = list(contrib = 20))**

The result is very nice for me. However, I have a problem that I need the name of those 20 vars in a list format that I can use later.
Do you know any way to do that, except writing down the name of top=20 vars from the biplot graph?

Thank you,
Hi [@luongthang1908][1], following what is stated in the factoextra package documentation, you can get the top N contributing variables to both PC1 and PC2 by doing this:

    pca_result1 = FactoMineR::PCA(X) # X is a dataframe/matrix with n rows (samples) and p cols (numeric values) 
    contrib_PC12 = pca_result1$var$contrib[,1:2]  # get contributions of each variable to PC1 and PC2
    eig_PC12 = pca_result1$eig[,1][1:2] # get the eigenvalues of both components
    contrib_total = apply(contrib_PC12, 1, function(x) {sum(x*eig_PC12)/sum(eig_PC12)}) # calculate the total contribution
    N = 20
    names(sort(contrib_total, decreasing = TRUE)[1:N]) -> topN_PC12

Then `topN_PC12` contains the variables you are interested in.


  [1]: https://www.biostars.org/u/56459/