0

我想获取/绘制每种葡萄酒类别(巴罗洛、格里诺利诺、巴贝拉)的特征的贡献。使用fviz_contrib我得到了所有类的贡献,如下面的 MWE 所示。但是我想知道是否以及如何计算/绘制按类/组单独过滤的它们。

library(ggbiplot)
library(factoextra)

data(wine)

wine.pca <- prcomp(wine, scale. = TRUE)

# plot the PCA 
print(ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, groups = wine.class, ellipse = TRUE, circle = TRUE))

# plot the contributions of the features for all wine classes
g.contr <- fviz_contrib(wine.pca, choice = "var", axes = 1:2, fill = "lightblue", color = "darkblue", top = 45)
print(g.contr)
4

1 回答 1

0

如果您分别计算每个类的 pca:

barolo.pca <- prcomp(wine[wine.class=="barolo", ], scale. = TRUE)
grignolino.pca <- prcomp(wine[wine.class=="grignolino", ], scale. = TRUE)
barbera.pca <- prcomp(wine[wine.class=="barbera", ], scale. = TRUE)
# plot the contributions of the features for each wine classes

g.contr <- fviz_contrib(barolo.pca, choice = "var", axes = 1:2, fill = "lightblue", color = "darkblue", top = 45)
print(g.contr)

g.contr <- fviz_contrib(grignolino.pca, choice = "var", axes = 1:2, fill = "lightblue", color = "darkblue", top = 45)
print(g.contr)

g.contr <- fviz_contrib(barbera.pca, choice = "var", axes = 1:2, fill = "lightblue", color = "darkblue", top = 45)
print(g.contr)
于 2016-11-01T12:45:06.850 回答