Use factoextra’s fviz_nbclust() to compare possible cluster counts before committing to K-means. It computes and visualizes either within-cluster sum of squares or silhouette criteria. section 11.5.2
The function accepts three practical arguments:
- data source: the dataset or prepared clustering data. section 11.5.2
- clustering algorithm: the algorithm used to form candidate clusters, not necessarily K-means. section 11.5.2
- method: the criterion, such as "wss" for within-cluster sum of squares or "silhouette" for silhouette coefficients. section 11.5.2
Compare payroll-and-wins cluster counts
options(scipen = 000) p3 <- fviz_nbclust(final_kmeans, kmeans, method = "wss") p4 <- fviz_nbclust(final_kmeans, kmeans, method = "silhouette") p3 + p4 + plot_layout(ncol = 1) The resulting plots place candidate cluster counts on the x-axis. The silhouette plot gives a definite optimum, while the WSS scree plot requires judgment; the sharpest WSS drop may suggest two clusters. section 11.5.2
