R 如何将二维数据分成两组

R 如何将二维数据分成两组,r,cluster-analysis,R,Cluster Analysis,我有测试数据如下 Test x y 1 4324.3329 484.6496 3 3258.4572 499.9621 4 4462.8230 562.7703 7 5173.4353 572.9492 8 4188.0244 530.8349 9 3557.5385 494.6672 10 2353.1382 517.5235 11 4944.2605 537.7489 15 3335.6628 488.4479 16 4059.0555 534

我有
测试
数据如下

Test
           x        y
1  4324.3329 484.6496
3  3258.4572 499.9621
4  4462.8230 562.7703
7  5173.4353 572.9492
8  4188.0244 530.8349
9  3557.5385 494.6672
10 2353.1382 517.5235
11 4944.2605 537.7489
15 3335.6628 488.4479
16 4059.0555 534.5479
17 4694.1778 531.7709
18 3213.8639 496.0062
19 4119.5348 516.3399
20 4267.7457 537.1041
22 4284.2706 503.8527
23 3019.6271 498.8519
35 2549.8743 503.5473
36 4976.5386 566.5985
37 2717.9942 513.2320
38 3545.2092 448.4752
40 3352.3206 457.7265
41 3198.0481 560.4075
42 1387.7531 395.7657
43  957.6421 296.1419
44 3168.8167 489.5333
45 2717.1015 478.6760
46 3694.8913 455.2763
47 4131.9760 519.9161
48 4366.2339 502.5977
49 4314.1003 486.7103
50 3818.1977 461.5844
52 3745.0532 467.7885
我添加散点图如下

gg <- ggplot(Test, aes(x = x, y = y))+
  geom_point()+
  stat_ellipse()
ggMarginal(
  gg,
  type = "boxplot",
  margins = "both",
  size = 5
)
print(gg)
#k-mean
km <- kmeans(Test,2)
library(cluster)
clusplot(Test, km$cluster, color=TRUE, shade=TRUE, labels=2, lines=0)
gg例如

set.seed(42)
km <- kmeans(Test,2)
ggplot(Test, aes(x = x, y = y,colour = factor(km$cluster)))+
 geom_point()+  
stat_ellipse(type = "norm", linetype = 2)
set.seed(42)

那么,就不要使用clusplot,而是按照您想要的方式绘制数据?非常感谢,是的。我想这就是我想要的。看起来左下角的两个异常值属于不同的组。为了说明这一点,我正在寻求更客观的方法。你能给我一些建议吗?你试过用离群点检测代替聚类吗?这些显然是异常值,我会在聚类之前删除它们。我不相信这里有两个集群的假设是正确的——我认为数据太少,无法拒绝单个集群的无效假设。非常感谢你的想法。另外,正如您所提到的,没有足够的数据划分为两个集群。我真的很感谢你的建议和评论。非常感谢你的例子。还有,除了k意味着聚类之外,还有其他聚类方法可以做到这一点吗?@imtaiky相信我,通过谷歌搜索,你可以得到更多关于R中聚类方法的信息,我无法解释。可能是一个开始。非常感谢你的链接。我真的很感激。