主成分分析 - 个体图

时间:2018-01-26 22:35:17

标签: r pca

我想知道是否有可能只在图表上显示选定的组,或者制作一些个人图表,因为在我的PCA中我有超过10个组,并且在一个图表上不易读。我将介绍虹膜数据的问题。

library(ggplot2)
library(factoextra)
data(iris)
res.pca <- prcomp(iris[, -5],  scale = TRUE)
fviz_pca_ind(res.pca, label="none", habillage=iris$Species)

因此,例如,我是否可以在图表上仅显示一组setos?或者只有setosa和versicolor?

1 个答案:

答案 0 :(得分:1)

fviz_pca_ind支持select.ind参数的数据子集:

select.ind
a selection of individuals/variables to be drawn. Allowed values are NULL or a list containing the arguments name, cos2 or contrib:

name: is a character vector containing individuals/variables to be drawn
cos2: if cos2 is in [0, 1], ex: 0.6, then individuals/variables with a cos2 > 0.6 are drawn. if cos2 > 1, ex: 5, then the top 5 individuals/variables with the highest cos2 are drawn.
contrib: if contrib > 1, ex: 5, then the top 5 individuals/variables with the highest cos2 are drawn

无法直接指定setosa,但您可以指定setosa行的索引。

setosa_indices <- rownames(iris[iris$Species == "setosa",])

fviz_pca_ind(res.pca, label = "none",
             habillage = iris$Species,
             select.ind = list(name = setosa_indices))

结果:

PCA analysis only for <code>setosa</code>