K-Means Clustering And Heatmap
1
1
Entering edit mode
10.6 years ago
Ming Tommy Tang ★ 3.9k

Hi everyone,

I was plotting a ChIP-seq data using the pheatmap, see code below:

km<- kmeans(m1,2) # determin how many cluster you want, I specify 2 here

m.kmeans<- cbind(m1, km$cluster) # combine the cluster with the matrix

dim(m.kmeans)
# [1] 903 602
# the last column is 602
o<- order(m.kmeans[,602]) # order the last column

m.kmeans<- m.kmeans[o,] # order the matrix according to the order of the last column

pheatmap( m.kmeans[,1:601], cluster_rows = F, cluster_cols = F, col= hmcols, breaks = bk, legend=FALSE, show_rownames=FALSE, show_colnames=FALSE)

It works fine for me, I clustered the data to two groups by specifying K=2, the problem is that group 1 sometimes shows up in the upper part of the heatmap, sometimes it shows up in the bottom part of the figure if I plot it several times.

I think it has to do with the assignment of the group number, say, the first group is assigned to 1, the other is assigned to 2. However, next time if you plot the same data, the first group assigned to 2, the other is assigned to 1. R randomly assigns the number to the groups.

How can control this?

Thank you every much!

heatmap • 17k views
ADD COMMENT
2
Entering edit mode
ADD COMMENT
0
Entering edit mode

Thank you! but I am not sure how to set the seed argument of the set.seed() function though...

ADD REPLY
0
Entering edit mode

you just do

set.seed(1) or set.seed(2)

or whatever. That's it...

ADD REPLY

Login before adding your answer.

Traffic: 3829 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6