How to match the clusters colours on a dendrogram, a silhouette and a cluster plot from the R factoextra package?

Viewed 130

I am visualising the results from hierarchical clustering using three plots i.e. 1) dendrogram 2) silhouette and 3) cluster as part of the ‘factoextra’ package.

I am using the ‘lancet’ colour palette for the dendrogram (fviz_dend) and would like to use the same colours with the fviz_silhoette and fviz_cluster plots. I have tried to use the ggsci package functions ‘scale_fill_lancet’ and ‘scale_color_lancet’ to achieve this but the colours don’t match.

Is there a way to match the colour of the clusters in these three plots?

Thank you!

library(factoextra)
library(ggsci)

data("USArrests")
df <- USArrests

# Compute hierarchical clustering
res.hc <- hcut(df, k = 5, hc_func = "hclust", hc_method = "complete", hc_metric = "euclidean",stand = TRUE)

# Visualize
fviz_dend(res.hc, rect = TRUE, cex = 0.5,palette = "lancet", graph = TRUE, rect_border = "lancet", rect_fill = TRUE, ggtheme = theme_void(), main = "") # dendrogram


fviz_cluster(res.hc, ggtheme = theme_void()) + scale_fill_lancet()+ scale_color_lancet() # scatter plot


fviz_silhouette(res.hc, ggtheme = theme_void())+ scale_fill_lancet()+ scale_color_lancet() # silhouette plot

0 Answers
Related