Open majpark21 opened 4 years ago
I have the same problem.
The solution is to give color in the good order in the dendrogram with the option palette and rect_border.
Before modification :
fviz_dend(res.hcpc, cex = 0.7, palette = "jco", rect = TRUE, rect_fill = TRUE, rect_border = "jco", labels_track_height = 1.8 ) fviz_cluster(res.hcpc, repel = TRUE, show.clust.cent = TRUE, palette = "jco", ggtheme = theme_minimal(), main = "Factor map")
After modification 👍 fviz_dend(res.hcpc, cex = 0.7, palette = c("#86868699", "#0073C299", "#EFC00099"), rect = TRUE, rect_fill = TRUE, rect_border = c("#86868699", "#0073C299", "#EFC00099"), labels_track_height = 1.8 ) fviz_cluster(res.hcpc, repel = TRUE, show.clust.cent = TRUE, palette = "jco", ggtheme = theme_minimal(), main = "Factor map")
Thanks! I actually arrived to a similar solution back then. Results of my inspections were that fviz_dend colors clusters "from left to right", whereas fviz_silhouette and fviz_cluster use the order of cluster first occurence in the list of individuals.
here is a generic method to achieve this: https://stackoverflow.com/a/69575597/5238559
I'm reporting 3 different representations for my clustering: colored dendrogram, PCA scatterplot and silhouette thanks to fviz_cluster, fviz_dend and fviz_silhouette respectively. I'm facing the following issue: the clusters aren't colored with the same colors across the plots. More specifically, it seems that the both the PCA and the silhouette plots follow the same color-cluster mapping, but not the dendrogram.
I've been digging in the source code a bit, appears that the dendrogram plot is produced by dendextend while the others by ggplot. I guess the difference of mapping originates from there.
I perform my cut using the
hcut
function, the same hcut object is then passed to the three visualization functions.Here is an example screenshot of my output:
As you can see, the smaller cluster is colored red in the dendrogram and blue in the silhouette and scatterplot.