title: Kmeans inter and intra cluster ordering
body: <p>I am wondering what other people are doing with K-means cluster ordering. I am making heatmaps (mainly of <a href="http://en.wikipedia.org/wiki/Chip-Sequencing" rel="noreferrer">ChIP-Seq</a> data) and getting nice looking figures with a custom heatmap function (based off of R's built in heatmap function). However, I'd like two improvements. The first is to order my clusters based on decreasing average value. For instance, the following code:</p>
  
  <pre><code>fit = kmeans(data, 8, iter.max=50, nstart=10)
  d = data.frame(data, symbol)
  d = data.frame(d, fit$cluster)
  d = d[order(d$fit.cluster),]
  </code></pre>
  
  <p>gives me a data.frame ordered on a clusters column. What is the best way to order the rows such that the 8 clusters are in order of their respective means?</p>
  
  <p>Second, do you recommend sorting the rows WITHIN each cluster from highest mean value to lowest? This will impose a more organized look onto the data, but may fool a non-cautious observer into inferring something that he perhaps should not. If you do recommend this, how would you do it most efficiently?</p>