颜色仅表示 PCA 组

color only mean group of PCA

假设我有一个 PCA(使用 FactoMineR 中的 prcomp() 或 PCA()。我想用黑色绘制每组的所有点,但仅标记和着色每组的平均点。对于例如,

library(FactoMineR)
library(factoextra)
iris
res.ACP<-PCA(iris[,c(1:3)],scale.unit = TRUE,ncp= 5)
fviz_pca_ind(res.ACP,geom.ind=c("point"),point.size=3,pointshape=16,
             col.ind=iris$Species,
             col="Set1",legend.title="Species",addlabel=TRUE, mean.point.size=5)

如何保持上面的平均点颜色,但将所有数据点绘制成黑色?理想情况下,我还想标记均值,然后删除图例。

感谢您的帮助。

这是一个可能的解决方案。

library(FactoMineR)
library(factoextra)
library(dplyr)

res.ACP <- PCA(iris[,c(1:3)], scale.unit = TRUE, ncp= 5)

df <- data.frame(res.ACP$ind$coord[,1:2], Species=iris$Species)
df <- df %>%
      group_by(Species) %>%
      summarize(Dim1=mean(Dim.1), Dim2=mean(Dim.2))

fviz_pca_ind(res.ACP, geom.ind=c("point"), point.size=3, pointshape=16,
             legend.title="Species", addlabel=TRUE) +
  geom_text(data=df, aes(x=Dim1, y=Dim2, label=Species, color=Species), 
            size=6, nudge_y=0.25) +
  geom_point(data=df, aes(x=Dim1, y=Dim2, color=Species), size=5)