PCA双标组个体

时间:2016-05-16 02:02:15

标签: r pca

我的数据中有很多人(n = 600)。我运行PCA并希望创建一个变量和个体的Biplot。我喜欢他们贡献的变量。这些人来自两个群体,我想根据这两个群体对这些点进行着色。我附上一个小例子。

library(FactoMineR)
library(factoextra)
data(decathlon2)
decathlon2.active <- decathlon2[1:23, 1:10]
head(decathlon2.active[, 1:6])
res.pca <- PCA(decathlon2.active, graph = FALSE)
fviz_pca_biplot(res.pca, col.var="cos", geom = "point") + scale_color_gradient2(low="white", mid="blue", 
                    high="red", midpoint=0.5) + theme_minimal()

res.pca_ind = data.frame(res.pca$ind)
res.pca_ind

问题; 1.我怎样才能为rownames SEBRLE&amp; NOOL为红色,黑色为res 2.将所有的rownames分配给2个因子中的1个(我不介意这个例子)并以不同的颜色着色。

部分答案;

sub = as.character(rownames(res.pca_ind))
decathlon3 = decathlon2[which(rownames(decathlon2) %in% sub),]

fviz_pca_biplot(res.pca, axes = c(1, 2), geom = c("point", "text"),
            label = "all", invisible = "none", labelsize = 2, pointsize = 2,
            habillage = decathlon3$Competition, addEllipses = FALSE,    ellipse.level = 0.95,
            col.ind = "black", col.ind.sup = "blue", alpha.ind = 1,
            col.var = "steelblue", alpha.var = 1, col.quanti.sup = "blue",
            col.circle = NULL, 
            select.var = list(name = NULL, cos2 = NULL, contrib= NULL), 
            select.ind = list(name = NULL, cos2 = NULL, contrib = NULL),
            jitter = list(what = "label", width = NULL, height = NULL))

然而,在我获得的地方,我正在失去。我无法找到使用habillage和select.var by contrib作为错误的方法:提供给离散比例的连续值不断出现。

0 个答案:

没有答案