r - 如何在 R 中绘制这个集群?

标签 r cluster-analysis

我有一堆不同点的 x 和 y 坐标以及它所属的集群。我如何绘制集群?这是我正在使用的示例:

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 分析。

最佳答案

以下可能有用:

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?

如果点像在使用 iris 数据的类似图中那样很好地聚类,它会显示得更好:
ggplot(iris, aes(Sepal.Length, Petal.Length, color=Species))+geom_point()+stat_ellipse()

enter image description here

关于r - 如何在 R 中绘制这个集群?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26076982/

相关文章:

R 并行中止所有 mclapply 操作

python - PySpark:AttributeError: 'PipelineModel'对象没有属性 'clusterCenters'

machine-learning - 假设数据正常但噪声均匀,如何从一组数据点中去除噪声?

python - 用 hexbin 覆盖多组数据

r - 如何直接从 R 中的网站读取 file.rar

r - 在 R 中传递 mongodb ISODate

r - 更改 ggplot 中时间序列间隙的线型

matlab - 聚类和matlab

algorithm - 无监督分类——得到特征向量

r - 根据R中数据框中第二列的值填充第三列