1

How to plot the second and third principal components after using prcomp?

More variance is explained by the second and third principal components on my variables of greatest interest.

Here is the code I'm using for the first and second:

res.pca <- prcomp(data3, scale = TRUE)
fviz_eig(res.pca)

fviz_pca_ind(res.pca,
             col.ind = "cos2", # Color by the quality of representation
             gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
             repel = TRUE     # Avoid text overlapping
)
1
  • 2
    It's easier to help you if you include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions. List all non-base R packages you are using. Commented Mar 4, 2021 at 20:31

1 Answer 1

3

You could use the axes argument to select the dimensions you want to display:

library(FactoMineR)
library(factoextra)

pca <- PCA(iris[,1:4])

fviz_pca_ind(pca,
             col.ind = "cos2", # Color by the quality of representation
             gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
             repel = TRUE,     # Avoid text overlapping
             axes = c(2, 3)
)

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.