I need a help to know how to find the optimal number of number of clusters using k-means cluster in R.
My code is
library(cluster)
library(factoextra)
#read data
data<-read.csv("..\file.txt",header=FALSE, sep=" ")
#determine number of clusters to use
k.max<- 22
wss <- sapply(2:k.max, function(k){kmeans(data, k, nstart=10 )$tot.withinss})
print(wss)
plot(2:k.max, wss, type="b", pch = 19, xlab="Number of clusters K", ylab="Total within-clusters sum of squares")
fviz_nbclust(data, kmeans, method = "wss") + geom_vline(xintercept = 3, linetype = 2)
I get the plot, but I still do not know how to find the number?
Thanks