Al14
Al14

Reputation: 1814

PCA analysis remove centroid

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.

Upvotes: 6

Views: 5065

Answers (2)

kurpav00
kurpav00

Reputation: 188

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)

Upvotes: 3

Marco Sandri
Marco Sandri

Reputation: 24252

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

Upvotes: 7

Related Questions