Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@decodebiology
Forked from crazyhottommy/heatmap_ChIP-seq_2.r
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save decodebiology/e3d0d9e200311cec7f1b to your computer and use it in GitHub Desktop.
Save decodebiology/e3d0d9e200311cec7f1b to your computer and use it in GitHub Desktop.
#The X axis is -3 kb to 3 kb around TSS.
#It turns out that the heatmap.2 function use default hclust ( Hierachical Clustering) to cluster the #matrix.
#alternatively, we can use K-means clustering to cluster the data and to see what's the pattern look like.
km<- kmeans(m1,2) # determine how many cluster you want, I specify 2 here
m1.kmeans<- cbind(m1, km$cluster) # combine the cluster with the matrix
dim(m1.kmeans)
# [1] 903 602
# the last column is 602
o<- order(m1.kmeans[,602]) # order the last column
m1.keans<- m1.kmeans[o,] # order the matrix according to the order of the last column
pheatmap( m1.kmeans[,1:601], cluster_rows = F, cluster_cols = F, col= hmcols, breaks = bk, legend=FALSE, show_rownames=FALSE, show_colnames=FALSE)
# no need to cluster by pheatmap, so I set cluster_rows and cluster_cols to FALSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment