gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 21:27:54 25 4
gpt4 key购买 nike

在我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com