r - PCA prcomp : how to get PC1 to PC3 graph

标签 r pca ggbiplot

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

最佳答案

ggbiplot 的 choices 参数就是您要查找的内容:

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')

enter image description here

# 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')

enter image description here

关于r - PCA prcomp : how to get PC1 to PC3 graph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34822424/

相关文章:

r - 在 R Studio 中从 csv 加载的行数有限

r - ggplot : color, geom_point 中的填充和大小

c++ - RCPP - 没有匹配函数调用 'transform'

r - 一个 ggplot2 图中的 PCA 图和方差比例表 - R

r - 错误 : Too few points to calculate an ellipse with 3 points?-R

python - 在Python中从图像中提取每个像素的x,y坐标

r - 在 ggbiplot 中指定箭头(线段)的颜色、透明度和位置

r - R:将校准轴添加到ggplot2中的PCA双图

r - 如何更改ggbiplot中椭圆的线型?

r - 以编程方式设置环境变量