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]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to