我想获得/绘制每种葡萄酒类别(barolo,grignolino,barbera)的功能贡献。使用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)
答案 0 :(得分: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)