Skip to content

Instantly share code, notes, and snippets.

@csetzkorn
Created September 23, 2017 20:00
Show Gist options
  • Save csetzkorn/88fccf1fdb5bfc27bc406f52d763a631 to your computer and use it in GitHub Desktop.
Save csetzkorn/88fccf1fdb5bfc27bc406f52d763a631 to your computer and use it in GitHub Desktop.
iris hierarchical clustering
library(dplyr)
library(ggplot2)
setwd('D:\\ToyData')
OrginalData <- read.table("https://s3.amazonaws.com/christiandata887342ac-a3ce-4600-94d0-9092f4a6bd20/IrisTabSepData/IrisData.txt",
header = TRUE, sep = "\t")
head(OrginalData)
SubsetData <- subset(OrginalData, select = c(
#"SepalLength"
#,"SepalWidth"
"PetalLength"
,"PetalWidth"
))
clusters = hclust(dist(SubsetData), method = 'average')
plot(clusters)
clusterCut <- cutree(clusters, 3)
table(clusterCut, OrginalData$Species)
ggplot(OrginalData, aes(PetalLength, PetalWidth, color = OrginalData$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