【问题标题】:PCA prcomp: how to get PC1 to PC3 graphPCA prcomp:如何获取 PC1 到 PC3 图
【发布时间】:2016-01-16 01:08:56
【问题描述】:

在我的 PCA 脚本(如下)中,我总是得到 PC1 与 PC2 的图表。

 mydata.pca <- prcomp(mydata.fixed, center = TRUE, scale. = TRUE)

 g <- ggbiplot(mydata.pca, obs.scale = 1, var.scale = 1, 
               groups = mysamples, ellipse = FALSE, 
               circle = FALSE, var.axes=FALSE) 
g <- g + scale_color_discrete(name = '') 
g <- g + theme(legend.direction ='horizontal', 
                legend.position = 'top') 
g <- g + theme_bw()

但是,当我运行类似:

summary(mydata.pca)

我看到了 PC1 到 PC4 的所有信息。如何更改我的 ggbioplot 脚本以获取 PC1 与 PC3 的图表?

【问题讨论】:

    标签: r pca ggbiplot


    【解决方案1】:

    ggbiplot 的选项参数是您正在寻找的:

    iris_pca <- prcomp(iris[, 1:4], center = TRUE, scale. = T)
    
    # PC1 vs PC 2
    
    ggbiplot(iris_pca, choices = c(1,2), obs.scale = 1, var.scale = 1, 
             groups = iris$Species, ellipse = TRUE, 
             circle = TRUE) + scale_color_discrete(name = '') + theme(legend.direction = 'horizontal', 
                   legend.position = 'top')
    

    # PC1 vs PC 3
    
    ggbiplot(iris_pca, choices = c(1,3), obs.scale = 1, var.scale = 1, 
             groups = iris$Species, ellipse = TRUE, 
             circle = TRUE) + scale_color_discrete(name = '') + theme(legend.direction = 'horizontal', 
                   legend.position = 'top')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多