data(iris)
dim(iris)
## [1] 150   5
ggplot(iris,aes(x = Sepal.Length, y = Sepal.Width, col= Species)) + geom_point()

set.seed(20)
irisCluster <- kmeans(iris[, 3:4], 3, nstart = 20)
table(irisCluster$cluster, iris$Species)
##    
##     setosa versicolor virginica
##   1     50          0         0
##   2      0         48         4
##   3      0          2        46
irisCluster$cluster <- as.factor(irisCluster$cluster)
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = irisCluster$cluster)) + geom_point()