rggbiplot

Keep mean points only for individual-groups in {factoextra} PCA biplot


I use the iris dataset as an example. I have set mean.point-TRUE which gives mean points for setosa (red round), versicolor (green triangle), virginica (blue square) as well as the factors (steelblue dot). I wish to make the steelblue dot to not appear while keeping everything else as is. How do I do this?

Here is the code:

library(tidyverse)
library(factoextra)
library(FactoMineR)


Groups<-as.factor(iris$Species)
res.pca<-prcomp(iris[-5], scale. = TRUE, center = TRUE)
fviz_pca_biplot(res.pca,
                mean.point=TRUE,
                pointsize=1,
                habillage=Groups,
                addEllipses = TRUE,
                label = FALSE)

And here is the output:

PCA_biplot


Solution

  • You can assign separate sizes to mean points. In your example, the blue point is the mean of the third group, so you can set the third position of the size vector to zero to hide the point:

    fviz_pca_biplot(## ... other arguments
                    ## but without mean.point
                    mean.point.size = c(5, 5, 0)
                    )
    

    (leave out the mean.point argument entirely, i. e. neither setting it to TRUE, FALSE or any other missingness value)