I am wondering what other people are doing with K-means cluster ordering. I am making heatmaps (mainly of ChIP-Seq 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:
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),]
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?
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?