我想获得/绘制每种类型葡萄酒(巴罗洛、格里尼奥利诺、巴贝拉)的特征贡献。使用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)
如果分别计算每个类的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)