代码之家  ›  专栏  ›  技术社区  ›  Elia

主成分分析-个体图

pca r
  •  2
  • Elia  · 技术社区  · 7 年前

    我想知道是否可以在图表上只显示选定的组,或者制作一些个人图表,因为在我的PCA中,我有10多个组,并且在一张图表上看不清。我将提出有关iris数据的问题。

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

    例如,我能在图上只显示seto的集合吗?还是只有刚毛和花色?

    1 回复  |  直到 7 年前
        1
  •  1
  •   m0nhawk Pasqui    7 年前

    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_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>