R draw kmeans clustering with heatmap

匿名 (未验证) 提交于 2019-12-03 01:58:03

问题:

I would like to cluster a matrix with kmeans, and be able to plot it as heatmap. It sounds quite trivial, and I have seen many plots like this. I have tried to google atround, but can't find a way round it.

I'd like to be able to plot something like panel A or B on this figure. Let say I have a matrix with 250 rows and 5 columns. I don't want to cluster the columns, just the rows.

m = matrix(rnorm(25), 250, 5)  km = kmeans(m, 10) 

Then how do I plot those 10 clusters as a heatmap ? You comments and helps is more than welcome.

Thanks.

回答1:

Something like the following should work:

set.seed(100) m = matrix(rnorm(10), 100, 5) km = kmeans(m, 10) m2 



回答2:

I think both the two figures should come from two figures combined. the left one is heatmap and the right is colored based on the cluster results. Of course, the data should be reordered by the result of cluster. BTW, the question is not similar with the two questions as commented below the question.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!