Skip to content

Instantly share code, notes, and snippets.

@nqbao
Created May 26, 2016 20:07
Show Gist options
  • Save nqbao/9edf7951df81be3f8c96a28459857ee7 to your computer and use it in GitHub Desktop.
Save nqbao/9edf7951df81be3f8c96a28459857ee7 to your computer and use it in GitHub Desktop.
library(ggplot2)
irisCluster = kmeans(iris[,1:3], nlevels(iris$Species), nstart=20)
iris$cluster = irisCluster$cluster
# build contingency table
t = table(iris$Species, iris$cluster)
ggplot(data=iris) + geom_point(aes(Sepal.Length, Sepal.Width, color=Species)) +
geom_point(aes(Sepal.Length, Sepal.Width), data=as.data.frame(irisCluster$centers), size=5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment