fviz_cluster - possible to manually assign colors to clusters?

2,815 views
Skip to first unread message

Sadia Haider

unread,
Jul 26, 2017, 7:20:05 AM7/26/17
to FactoMineR users
I am running HCPC after MCA and would like to manually assign colors to my 3 clusters ("darkgreen" for cluster 1, "orange" for cluster 2, "red" for cluster 3) . Please could you tell me if this is possible using fviz_cluster? Many thanks!

Fabian Mundt

unread,
Jul 26, 2017, 7:35:11 AM7/26/17
to FactoMineR users
Hi Sadia,

since factoextra is build upon ggplot2, this is no problem:

library(FactoMineR)
library(factoextra)

data(tea)

res_mca <- MCA(tea[, 1:5], graph = FALSE)

res_hcpc <- HCPC(res_mca, nb.clust = 3, graph = FALSE)

fviz_cluster(res_hcpc, ) +
  scale_colour_manual(values = c("darkgreen", "orange", "red")) +
  scale_fill_manual(values = c("darkgreen", "orange", "red")) 

All the best,
Fabian

Sadia Haider

unread,
Jul 26, 2017, 10:11:40 AM7/26/17
to FactoMineR users
Fantastic! Thank you so much - much appreciated!
Reply all
Reply to author
Forward
0 new messages