Question: Does anybody know how to add a color side bar which will be re-ordered by the clustering in pheatmap
1
gravatar for sw.arker
5.4 years ago by
sw.arker60
Germany
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: https://www.dropbox.com/s/qc8zjpgcimo71mu/sample.jpg

 

 

 

heatmap R • 7.8k views
ADD COMMENTlink modified 15 months ago by Kevin Blighe51k • written 5.4 years ago by sw.arker60
1

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

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

thanks! I will try it!!

ADD REPLYlink written 5.4 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.4 years ago by Malachi Griffith18k
4
gravatar for Kevin Blighe
15 months ago by
Kevin Blighe51k
Kevin Blighe51k 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)),
      row.names=colnames(data))
colnames(metadata) <- c("casecontrol","condition")
metadata
          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,
      annotation_col=metadata)

Screen_Shot_2018_08_16_at_16_55_06

Kevin

ADD COMMENTlink written 15 months ago by Kevin Blighe51k
Please log in to add an answer.

Help
Access

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