0
我想绘制K均值聚类。以下是我使用的代码。如何在K中显示行名称意味着R中的聚类图?
library(cluster)
library(fpc)
data(iris)
dat <- iris[, -5] # without known classification
# Kmeans clustre analysis
clus <- kmeans(dat, centers=3)
clusplot(dat, clus$cluster, color=TRUE, shade=TRUE,
labels=2, lines=0)
我得到下面的图片:
取而代之的行号,我想这与字符的行名称显示。我明白这幅画是生产有一个像下面的数据:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
6 5.4 3.9 1.7 0.4 setosa
但是好心假设我的工作数据就像下面
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
Flower1 5.1 3.5 1.4 0.2 setosa
Flower2 4.9 3.0 1.4 0.2 setosa
Flower3 4.7 3.2 1.3 0.2 setosa
Flower4 4.6 3.1 1.5 0.2 setosa
Flower5 5.0 3.6 1.4 0.2 setosa
Flower6 5.4 3.9 1.7 0.4 setosa
我想有flower1,flower2等在可视化而不是序列号。有没有办法做到这一点?
谢谢。
感谢您的解决方案。这工作。 – Arun