我有多个聚类图,我想添加一个标签,显示图中每个聚类的聚类内方差。我尝试使用geom_label添加文本,但这对我来说似乎不起作用。我试着查看fviz_cluster文档,但我似乎无法找到任何有助于我想要的东西 这是我的代码:
k2 <- kmeans(protein.scaled, centers = 2,
iter.max = 1, nstart = 25)
k3 <- kmeans(protein.scaled, centers = 3,
iter.max = 1, nstart = 25)
k4 <- kmeans(protein.scaled, centers = 4,
iter.max = 1, nstart = 25)
k5 <- kmeans(protein.scaled, centers = 5,
iter.max = 1, nstart = 25)
k6 <- kmeans(protein.scaled, centers = 6,
iter.max = 1, nstart = 25)
k1_4 <- KMeans(protein.scaled, centers=2,
iter.max=100, num.seeds = 1)
p2 <- fviz_cluster(k2, geom = "point", data = protein.scaled,
xlab = "Cereals", ylab = "RedMeats",
stand = FALSE) + ggtitle("k = 2") +
geom_label(aes(label = k2$withinss/(nrow(protein.scaled)-2)),
position = "identity")
p2
p3 <- fviz_cluster(k3, geom = "point", data = protein.scaled,
xlab = "Cereals", ylab = "RedMeats") + ggtitle("k = 3")
p4 <- fviz_cluster(k4, geom = "point", data = protein.scaled,
xlab = "Cereals", ylab = "RedMeats") +
ggtitle("k = 4")
p5 <- fviz_cluster(k5, geom = "point", data = protein.scaled,
xlab = "Cereals", ylab = "RedMeats") + ggtitle("k = 5")
p6 <- fviz_cluster(k6, geom = "point", data = protein.scaled,
xlab = "Cereals", ylab = "RedMeats") + ggtitle("k = 6")
pk4 <- fviz_cluster(k1_4, geom = "point", data = protein.scaled,
xlab = "Cereals", ylab = "RedMeats") +
ggtitle("k=6 run 100 times")
感谢您的帮助!