2016-06-01 29 views
2

我想用ggbiplot来绘制PCA结果,我如何绘制补充变量? 我发现this discussion马华的结果,但我想有箭头,以及...ggbiplot中的补充变量PCA

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

我试过你的代码,并没有重现你的错误,但有其他问题。我搜索了PCA(),发现用于做PCA的软件包是FactoMineR。看文档之后,我也改变scale.scale.unitquanti.supquali.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