在我的 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')
# 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')
关于r - PCA prcomp : how to get PC1 to PC3 graph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34822424/