R 使用距离质心的k-均值绘制簇

R 使用距离质心的k-均值绘制簇,r,cluster-analysis,k-means,R,Cluster Analysis,K Means,我正在尝试创建一个类似于以下内容的情节: 这里有三个簇,所有数据点(圆)都是根据它们与质心的欧几里德距离绘制的。使用这张图片很容易看出,类别2中的5个样本最终出现在错误的簇中 我正在使用kmeans运行k-means,不知道如何绘制这种类型的图形 例如,我们可以使用iris数据集 > iri <- iris > cl <- kmeans (iri[, 1:4], 3) > cl K-means clustering with 3 clusters of sizes

我正在尝试创建一个类似于以下内容的情节:

这里有三个簇,所有数据点(圆)都是根据它们与质心的欧几里德距离绘制的。使用这张图片很容易看出,类别2中的5个样本最终出现在错误的簇中

我正在使用
kmeans
运行k-means,不知道如何绘制这种类型的图形

例如,我们可以使用iris数据集

> iri <- iris
> cl <- kmeans (iri[, 1:4], 3)
> cl
K-means clustering with 3 clusters of sizes 38, 62, 50

Cluster means:
  Sepal.Length Sepal.Width Petal.Length Petal.Width
1     6.850000    3.073684     5.742105    2.071053
2     5.901613    2.748387     4.393548    1.433871
3     5.006000    3.428000     1.462000    0.246000

Clustering vector:
  [1] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
 [40] 3 3 3 3 3 3 3 3 3 3 3 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
 [79] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 1 1 1 1 2 1 1 1 1 1 1 2 2 1 1
[118] 1 1 2 1 2 1 2 1 1 2 2 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 2

Within cluster sum of squares by cluster:
[1] 23.87947 39.82097 15.15100
 (between_SS / total_SS =  88.4 %)

Available components:

[1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
[6] "betweenss"    "size"         "iter"         "ifault"      
>iri cl
K-均值聚类,3个大小为38、62、50的聚类
集群是指:
萼片。长萼片。宽花瓣。长花瓣。宽
1     6.850000    3.073684     5.742105    2.071053
2     5.901613    2.748387     4.393548    1.433871
3     5.006000    3.428000     1.462000    0.246000
聚类向量:
[1] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
[40] 3 3 3 3 3 3 3 3 3 3 3 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
[79] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 1 1 1 1 2 1 1 1 1 1 1 2 2 1 1
[118] 1 1 2 1 2 1 2 1 1 2 2 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 2
簇内按簇计算的平方和:
[1] 23.87947 39.82097 15.15100
(介于两者之间/总数=88.4%)
可用组件:
[1] “群集”“中心”“totss”“带INSS”“tot.带INSS”
[6] 介于“大小”和“iter”之间的结果
图像来源:但发起者似乎没有使用
kmeans

我怀疑使用
kmeans
这可能不可行,因为它没有提供到质心的距离。是否有其他方式以这种方式或类似方式显示数据