3

在我的 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 的图表?

4

1 回答 1

4

的选择参数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')

在此处输入图像描述

于 2016-01-16T02:07:51.933 回答