2016-06-01 66 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