Suzanne Matthews
2009-Jul-23 16:45 UTC
[R] using k-means clustering in conjunction with heatmap.2 function
Hello, I am trying to create a heatmap that clusters based on a k-means scheme rather than a hierarchical clustering scheme. Suppose I have the following input data, located in sample.table: x1 x2 x3 x4 x1 17.198 16.306 16.806 16.374 x2 14.554 10.866 15.780 14.596 x3 14.374 14.118 14.569 17.352 x4 17.505 14.596 15.738 14.070 By using the heatmap.2 function as follows, I can create a heatmap using hierarchical clustering: library(gplots) x=read.table('sample.table', header=TRUE) mat=data.matrix(x) heatmap.2(mat, col=redgreen(75), trace="none") However, I am now interested in trying to show a heatmap in which the data is clustered using k-means. By looking at some previous posts on the mailing lists, and the documentation, I've attempted to cluster my data using kmeans using the following modified script: x=read.table('sample.table', header=TRUE) mat=data.matrix(x) km <-kmeans(t(scale(t(mat))), 3); km$cluster heatmap.2(mat, col=redgreen(75), hclustfun=km, trace="none") However, I'm not sure what I need to modify in the heatmap.2 list of parameters to have the matrix reflect a k-means clustering. The above usage will throw an error, since "km" is not a valid heirarchacal clustering function. My question is, what should the heatmap.2() function look like in order for it to show kmeans clustering? I'm not even sure if I'm using the kmeans function in a way that's optimal for producing heatmaps. I saw a post related to something like this in June of 2006, but I was not able to get any further than I what I've shown you above. I would greatly appreciate it if someone could point me in the right direction. One part of me also isn't even sure if k-means makes sense in this context. I would really appreciate your opinions related to this. Thanks in advance for your time! -SM [[alternative HTML version deleted]]
Reasonably Related Threads
- AJAX in conjunction with partials
- Is anybody using XEN in conjunction with Asterisk and/or Openser?
- Re: blockcommit --pivot does not succeed in conjunction with qemu 5.0.0
- bind segfault in conjunction with dbus - what to change?
- trying to get the debug version of httpd so I can use it in conjunction with gdb. [SOLVED]