0

I have a expression matrix containing three groups. I need to draw or split the heat-map with specific range of column.

Total number of colums: 151 where 1st column is gene ids
Group1: 2:40
Group2: 41:80
Group3: 81:151

I searched for splitting the heatmap and I got some hits like this. But they are based on specific clusters. I need to give my range as (2:40, 41:80, 81:151) for splitting or making boundary for the heatmap

  • 1
    please [make your question reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Wimpel Feb 19 '20 at 06:37

1 Answers1

0

Something like this

library(pheatmap)
mat = cbind(genes=1:100,
matrix(rnorm(150*100,mean = rep(1:3,c(39*100,40*100,71*100))),ncol=150))
colnames(mat)[2:ncol(mat)] = paste0("col",1:150)

You need to know how many are in each group, from what you provided, i counted this:

Group1: 39 Group2: 40 Group3: 71

So you need to make a data.frame that has the same row names as your matrix, and tell it which is group1,2 etc.

DF = data.frame(Groups=rep(c("Group1","Group2","Group3"),c(39,40,71)))
rownames(DF) = colnames(mat)[2:ncol(mat)]

Then we plot, mat[,-1] means excluding the first column, you need to specify where to insert the gap, and for your example it is at 39,79 and 80 because we excluded the first column:

pheatmap(mat[,-1],cluster_cols=FALSE,
annotation_col=DF,gaps_col = cumsum(c(39,40,71)))

enter image description here

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
  • I tried the above code and it is working but it failed to display the gene names. Sample names are given at the bottom but I require gene names on the right side –  Feb 20 '20 at 06:16
  • 1
    Oh right, you have to assign the row names to the matrix or dataframe before plotting. try rownames(mat) = mat[,1] ; then run it again – StupidWolf Feb 20 '20 at 07:40