title: How to label k-means clusters in r
body: <p>The wikibook on kmeans clustering (<a href="http://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Clustering/K-Means" rel="nofollow noreferrer">http://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Clustering/K-Means</a>) gives an example cluster analysis : </p>
  
  <p>Can the code be amended so that a label is generated from each cluster? Below graph does not indicate what is being compared. There are three clusters but what are the names of each cluster ?</p>
  
  <p><img src="https://i.stack.imgur.com/yrM6b.jpg" alt="enter image description here"></p>
  
  <p>Here is the code that generates the graph : </p>
  
  <pre><code># import data (assume that all data in "data.txt" is stored as comma separated values)
  x &lt;- read.csv("data.txt", header=TRUE, row.names=1)
  
  # run K-Means
  km &lt;- kmeans(x, 3, 15)
  
  # print components of km
  print(km)
  
  # plot clusters
  plot(x, col = km$cluster)
  # plot centers
  points(km$centers, col = 1:2, pch = 8)
  </code></pre>