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
)
Mikael Jagan
  • 9,012
  • 2
  • 17
  • 48
user2795569
  • 343
  • 2
  • 9
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-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. – MrFlick Mar 04 '21 at 20:31

1 Answers1

2

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

Waldi
  • 39,242
  • 6
  • 30
  • 78