2

I’m trying to extract the points (IDs) that occur in both ellipses from the graph produced by the function clusplot below.

    library(cluster)
    # Creates a sample data set.
    y <- matrix(runif(5000,max=1,min=0), 1000, 5, dimnames=list(paste("g", 1:1000, sep=""), paste("t", 1:5, sep=""))) 
    kc <- kmeans(y, centers=2)
    # plot kmeans clusters
    clusplot(y, kc$cluster, color=TRUE, shade=TRUE,labels=4, lines=0)

enter image description here

madhead
  • 31,729
  • 16
  • 153
  • 201
Samuel Shamiri
  • 137
  • 2
  • 9
  • 1
    A crude way would be to extract `z` object from `clusplot.default` result and convert it to `sp` objects of `SpatialPolygon` and make a `SpatialPoints` object from `s.x.2d` and use some geometry magic from `rgeos` package to infer points. – Roman Luštrik Apr 17 '15 at 15:09
  • hmmm. they are not supposed to be ellipses at all. But have a look at the `kc` object! – Has QUIT--Anony-Mousse Apr 18 '15 at 05:36
  • 'kc$cluster' has k clusters (k=2), each row (ID) belong's to a single cluster. 'clustplot' has a nice visualization (ellipses) and not kc. – Samuel Shamiri Apr 18 '15 at 07:18

0 Answers0