ggbiplot PCA中的补充变量

时间:2016-06-01 11:02:20

标签: r pca ggbiplot

我试图用ggbiplot绘制PCA结果,我该如何绘制补充变量? 我找到了this discussion的MCA结果,但我也希望得到箭头......

 data(wine)
 wine.pca <- PCA(wine, scale. = TRUE, quanti.sup = c(4,5))
 plot(wine.pca)
 ggbiplot(wine.pca)

With plot.PCA With gbiplot

此外,此代码给出了一个错误:

 1: In sweep(pcobj$ind$coord, 2, 1/(d * nobs.factor), FUN = "*") :
    STATS is longer than the extent of 'dim(x)[MARGIN]'
 2: In sweep(v, 2, d^var.scale, FUN = "*") :
    STATS is longer than the extent of 'dim(x)[MARGIN]' 

1 个答案:

答案 0 :(得分:1)

我尝试了您的代码并没有重现您的错误,但有其他问题。我用Google搜索PCA(),发现用于执行PCA的包是FactoMineR。查看文档后,我还将scale.更改为scale.unit,将quanti.sup更改为quali.sup,并为分类变量提供了正确的列。

library(FactoMineR)
data(wine)
wine.pca <- PCA(wine, scale.unit = TRUE, quali.sup = c(1,2))
plot(wine.pca)
ggbiplot(wine.pca)

那应该给出正确的输出。

enter image description here