使用 prcomp

问题描述

如何绘制使用 prcomp 后的第二和第三主成分。

我最感兴趣的变量的第二和第三主成分解释了更多的方差。

这是我用于第 1 次和第 2 次的代码

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
)

解决方法

您可以使用 axes 参数来选择要显示的维度:

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