2014-09-27 67 views
4

我有一堆x和y坐标的不同点和它属于的集群。我如何绘制群集?这里是我工作的一个样本:如何在R中绘制这个簇?

x-values y-values cluster 
3   5   0 
2   3   1 
1   4   0 
8   3   0 
2   2   2 
7   7   2 

如何绘制点的散点图为“*”或“+”和颜色色调的集群,它看起来像:

enter image description here

注意我没有进行PCA分析。

+0

看这里:http://stackoverflow.com/questions/15376075/cluster-analysis-in-r-determine-the-optimal-number-of-clusters/15376462#15376462 – 2014-09-27 17:01:12

回答

7

以下可能是有用的:

library(ggplot2) 
ggplot(ddf, aes(x.values, y.values, color=factor(cluster)))+geom_point() 

enter image description here

集聚区可以stat_ellipse可以看到()。他们不是用这个数据可以看出,由于以下错误:

ggplot(ddf, aes(x.values, y.values, color=factor(cluster)))+geom_point()+stat_ellipse() 
Too few points to calculate an ellipse 
Too few points to calculate an ellipse 
Too few points to calculate an ellipse 
geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic? 

它会显示更好,如果点在类​​似的情节使用虹膜数据以及集群为:

ggplot(iris, aes(Sepal.Length, Petal.Length, color=Species))+geom_point()+stat_ellipse() 

enter image description here

+0

如果我有两个群集列:预测群集和正确的群集?我将如何用ggplot来表示这样一个圈出来,另一个被遮蔽?另外,如果我有两列:x,y坐标对应于集群的质心怎么办?我如何将它作为'+'或'*'添加到图表中? – cooldood3490 2014-09-30 05:00:52

+0

预测和正确的聚类可以用不同的颜色显示。我不清楚第二个问题。最好的办法是以可重现的例子开始另一个问题。 – rnso 2014-09-30 11:04:06

1

您可以使用clusplotcluster包:

clusplot(dat[,1:2], dat$cluster, color=TRUE, shade=TRUE, labels=2, lines=0) 

其中DAT是你的矩阵。

enter image description here