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)
Kevin
I do this, but it's not pretty. I use layout() and image() to make my own image plots.
thanks! I will try it!!
This post might be relevant: How Do I Draw A Heatmap In R With Both A Color Key And Multiple Color Side Bars?