Skip to content

Instantly share code, notes, and snippets.

@helgejo
Last active November 19, 2017 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helgejo/186408fb79d8e9b89fca to your computer and use it in GitHub Desktop.
Save helgejo/186408fb79d8e9b89fca to your computer and use it in GitHub Desktop.
clusters <- hclust(dist(iris[, 3:4]))
plot(clusters)
clusterCut <- cutree(clusters, 3)
table(clusterCut, iris$Species)
clusters <- hclust(dist(iris[, 3:4]), method = 'average')
plot(clusters)
clusterCut <- cutree(clusters, 3)
table(clusterCut, iris$Species)
ggplot(iris, aes(Petal.Length, Petal.Width, color = iris$Species)) +
geom_point(alpha = 0.4, size = 3.5) + geom_point(col = clusterCut) +
scale_color_manual(values = c('black', 'red', 'green'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment