5

I am using fviz_pca_ind to make PCA plot see below.

 fviz_pca_ind(res.pca,  geom="point",  pointsize = 1, habillage=iris$Species, addEllipses=TRUE, ellipse.level=0.95
             , palette = c("green", "orange", "grey")) 

I want to remove the centroid but maintain the different colors and ellipses that I get with habillage=iris$Species.

col.ind requires a vector with a number of elements equal to the lines number.

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
Al14
  • 1,734
  • 6
  • 32
  • 55

2 Answers2

7

Here is a way to remove centroids:

library(factoextra)
data(iris)
res.pca <- prcomp(iris[, -5],  scale = TRUE)
fviz(res.pca, element="ind", geom="point",  pointsize = 1, 
              habillage=iris$Species, addEllipses=TRUE, ellipse.level=0.95, 
              palette = c("green", "orange", "grey"), invisible="quali") 

enter image description here

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
0

There is in fact a much simpler way directly in the fviz_pca_ind (and fviz_pca_biplot) function: "To remove the group mean point, specify the argument mean.point = FALSE." (source). So:

library(factoextra)
data(iris)
res.pca <- prcomp(iris[, -5],  scale = TRUE)
fviz_pca_ind(res.pca,  geom="point",  pointsize = 1, habillage=iris$Species, addEllipses=TRUE,
ellipse.level=0.95, palette = c("green", "orange", "grey"), mean.point=F)
kurpav00
  • 138
  • 6
  • I get an error message `Error in `purrr::pmap()`: ℹ In index: 1. ℹ With name: y. Caused by error in `if (mean.point) ...`: ! the condition has length > 1 Run `rlang::last_trace()` to see where the error occurred.` – Julien Aug 26 '23 at 09:32