1

How to plot the 2nd and 3rd principle component after using prcomp.

More variance is explained by the 2nd and 3rd principle component on my variables of greatest interest.

Here is the code im using for the 1st and 2nd.

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
)
Waldi
  • 31,868
  • 6
  • 18
  • 66
user2795569
  • 333
  • 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

1

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
  • 31,868
  • 6
  • 18
  • 66