我有一堆不同点的 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
如何将点的散点图绘制为 '*' 或 '+' 并为集群着色,使其看起来像:
注意我不是在做 PCA 分析。
最佳答案
以下可能有用:
library(ggplot2)
ggplot(ddf, aes(x.values, y.values, color=factor(cluster)))+geom_point()
可以使用 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()
关于r - 如何在 R 中绘制这个集群?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26076982/