rfactoextra

In `factoextra` `PCA`, how to add `max.overlaps` paramater


In factoextra PCA, how to add max.overlaps paramater? Like input max.overlaps=100 to PAC will failde

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

PCA(decathlon2[,- ncol(decathlon2)])

In my actual sample , I met below message in PCA, so i think add max.overlaps to PCA function. The actual data is harder to reproduce .

ggrepel: 15 unlabeled data points (too many overlaps). Consider increasing max.overlaps 

Solution

  • I don't see any (easy) option to set max.overlaps. First, there is no way to pass max.overlaps to the the default plot.PCA method. Instead plot.PCA uses the default from geom_text_repel. Second, when you call PCA the plots are printed by default but not returned. Hence, there is no easy way to set max.overlaps by manipulating the ggplot objects.

    Instead I would suggest to set graph=FALSE and instead use e.g. fviz_pca_ind and fviz_pca_var from factoextra to create the plots. While these functions also do not allow to set max.overlaps they default to max.overlaps=Inf. And if required they allow for further manipulation of the ggplot object.

    library(factoextra)
    library(FactoMineR)
    
    pca <- PCA(decathlon2[, -ncol(decathlon2)], graph = FALSE)
    
    fviz_pca_ind(pca, repel = TRUE)
    

    fviz_pca_var(pca, repel = TRUE)