2

I want to change the colours of my clusters but maintain the shape. habillage=iris$Species changes both colour and shape, what can to change only colours?

library("devtools")
install_github("kassambara/factoextra")
library("factoextra")
res.pca <- prcomp(iris[, -5],  scale = TRUE)
fviz_pca_ind(iris.pca,  geom="point",  pointsize = 1, habillage=iris$Species, addEllipses=TRUE, ellipse.level=0.95)
StupidWolf
  • 45,075
  • 17
  • 40
  • 72
Al14
  • 1,734
  • 6
  • 32
  • 55

1 Answers1

4

fviz_pca() works like ggplot plots, hence, for changing shapes you can use the aesthetic mappings of ggplot, e.g., for changing shapes. Concerning colors, the documentation called by ?fviz_pca_ind tells you that you can change colors via palette.

fviz_pca_ind(res.pca,  geom="point",  pointsize = 1, habillage=iris$Species, addEllipses=TRUE, ellipse.level=0.95
             , palette = c("green", "orange", "grey") #change colors
             ) + 
             scale_shape_manual(values=c(2, 8, 11)) #change shapes
Manuel Bickel
  • 2,156
  • 2
  • 11
  • 22
  • I am trying to use palette without `habillage=iris$Species` but it does not work, why do I need it? – Al14 Oct 25 '17 at 14:32
  • I am not an expert with fviz, but from my understanding you need to tell the function at some point, by which factors you group your data. This is handled by habillage. If you do not use habillage `fviz`does not "know" that there are three groups, hence, you cannot use settings, such as palette, that require a certain number of groups (three in your example). – Manuel Bickel Oct 25 '17 at 14:53