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

577 Views Asked by At

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

There are 1 best solutions below

0
On BEST ANSWER

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