library(dplyr)
library(ggplot2)
OrginalData <- read.table("https://s3.amazonaws.com/Somewhere/IrisTabSepData/IrisData.txt",
header = TRUE, sep = "\t")
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'))
是否可以向原始dataframe OrginalData中添加一个额外的列,该列包含在上述代码(3,在本例中为1-3)中创建的集群,并将其写入csv文件?