Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot this cluster in R?

I have a bunch of x and y coordinates of different points and the cluster it belongs to. How do I plot the clusters? Here's a sample of what I'm working with:

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

How do I plot a scatterplot of the points as a '*' or '+' and color shade the clusters so that it looks like:

enter image description here

Note I'm not doing a PCA analysis.

like image 427
cooldood3490 Avatar asked Sep 27 '14 16:09

cooldood3490


1 Answers

Following may be useful:

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

enter image description here

Cluster areas can be seen with stat_ellipse(). They are not seen with this data due to following errors:

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?

It will show better if points are well clustered as in a similar plot using iris data:

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

enter image description here

like image 86
rnso Avatar answered Oct 26 '22 10:10

rnso