Question: Does anybody know how to add a color side bar which will be re-ordered by the clustering in pheatmap
gravatar for sw.arker
5.7 years ago by
sw.arker60 wrote:

Hello, I am recently starting to use pheatmap since it can draw more decent heatmap (personal opinion) in comparison with heatmap.2 or heatplot.. however, I want to add a color side bar (on top of the heatmap) as I did in heatmap.2 with different color assigned to each group of sample and re-ordered by the clustering in heatmap. I know in heatmap.2 I can use "ColSideColors", but in pheatmap I could use "annotation"; but I didn't figure out how to get it work, please help!! many thanks!! 

the data format like this, and I want the genes under 4 different conditions assigned the same color but re-ordered in heatmap by clustering:

data format:




heatmap R • 8.4k views
ADD COMMENTlink modified 19 months ago by Kevin Blighe56k • written 5.7 years ago by sw.arker60

I do this, but it's not pretty. I use layout() and image() to make my own image plots.

ADD REPLYlink written 5.7 years ago by Madelaine Gogol5.1k

thanks! I will try it!!

ADD REPLYlink written 5.7 years ago by sw.arker60

This post might be relevant: How Do I Draw A Heatmap In R With Both A Color Key And Multiple Color Side Bars?

ADD REPLYlink written 5.7 years ago by Malachi Griffith18k
gravatar for Kevin Blighe
19 months ago by
Kevin Blighe56k
Kevin Blighe56k wrote:

Use annotation_col, as exemplified here: A: DESeq2 pheatmap returns Error in check.length("fill") : 'gpar' element 'fill' mu

The rownames of your object passed to annotation_col should be the same as the colnames of your object that is being clustered.

A reproducible example:

#Create random data
data <- replicate(20, rnorm(50))
rownames(data) <- paste("Gene", c(1:nrow(data)))
colnames(data) <- paste("Sample", c(1:ncol(data)))

metadata <- data.frame(
      c(rep("case", ncol(data)/2), rep("control", ncol(data)/2)),
      c(rep("cond1", ncol(data)/4), rep("cond2", ncol(data)/4), rep("cond3", ncol(data)/4), rep("cond4", ncol(data)/4)),
colnames(metadata) <- c("casecontrol","condition")
          casecontrol condition
Sample 1         case     cond1
Sample 2         case     cond1
Sample 3         case     cond1
Sample 4         case     cond1
Sample 5         case     cond1
Sample 6         case     cond2
Sample 7         case     cond2
Sample 8         case     cond2
Sample 9         case     cond2
Sample 10        case     cond2
Sample 11     control     cond3
Sample 12     control     cond3
Sample 13     control     cond3
Sample 14     control     cond3
Sample 15     control     cond3
Sample 16     control     cond4
Sample 17     control     cond4
Sample 18     control     cond4
Sample 19     control     cond4
Sample 20     control     cond4

out <- pheatmap(data, 
      show_rownames=T, cluster_cols=T, cluster_rows=T, scale="row",
      cex=1, clustering_distance_rows="euclidean", cex=1,
      clustering_distance_cols="euclidean", clustering_method="complete", border_color=FALSE,



ADD COMMENTlink written 19 months ago by Kevin Blighe56k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1250 users visited in the last hour