problem changing color for annotations
Hi everyone,
I am doing a pheatmap with deseq2 data, and I'm not able to change the colors of the column annotations. I have 12 samples (columns) grouoped in 4 conditions, and I'm doing pair-wise comparisons like this, below. Now, my intention is change de default color of the group annotation to for example orange and skyblu (you can see in the script) but it seems doesn't work, but I don't get any error message. I hope someone can help me out :) Thanks!!
> > sampleTable
sample NamefileName condition
1 1A 1A_gene_strict.tsv WT_NS
2 2A 2A_gene_strict.tsv WT_NS
3 3A 3A_gene_strict.tsv WT_NS
4 1B 1B_gene_strict.tsv WT_ST
5 2B 2B_gene_strict.tsv WT_ST
6 3B 3B_gene_strict.tsv WT_ST
7 6A 6A_gene_strict.tsv KO_NS
8 7A 7A_gene_strict.tsv KO_NS
9 8A 8A_gene_strict.tsv KO_NS
10 6B 6B_gene_strict.tsv KO_ST
11 7B 7B_gene_strict.tsv KO_ST
12 8B 8B_gene_strict.tsv KO_ST
levels <- unique(sampleTable$condition)
ll <- length(levels)
for (i in 1:(ll-1)) {
for (j in (i+1):ll) {
l1 <- toString(levels[i])
l2 <- toString(levels[j])
conditions = c(l1, l2)
conds = subset(sampleTable, sampleTable$condition %in% conditions)
samples = conds$sample
df = data.frame(condition=conds$condition)
rownames(df) = samples
my_colour = list(df=c(l1="orange", l2="skyblue"))
res <- results(dds, contrast=c("condition", l2, l1))
res$FoldChange <- 2^res$log2FoldChange
sig <- subset(res, res$padj < cutoff)
subcounts <- subset(ncounts, rownames(ncounts) %in% rownames(sig))
subcounts <- subcounts[,rownames(df)]
lsubcounts <- log2(subcounts+1)
pheatmap(mat=lsubcounts, color=hmcol, border_color=F, scale="row", cluster_cols=T,
cluster_rows=T, fontsize_row=9, annotation_col=df, annotation_colors=my_colour,
show_rownames=F, show_colnames=T, annotation_names_col=F, annotation_names_row=F)
}
}
• 322 views
•
link
0 answers
No answers yet.
Log in to answer this question.
Use the
101010box to format the R code and use theCopy image address(Google Chrome) link for sharing images.Done, thank you for the hint!
It's a bit hard to see within the loop structure, and without showing your error message, but I believe your problem may be that when you create the list to define your colors:
The internal variable should be named like the column of the annotation that you are using (
df) and want to color. So try changing it to this:Thanks Papyrus. I've edited my post to understand better those levels. I tried to change my line by yours, but it is not working (substituting "df" by "condition" ), I have still the defaults colours... :(
Here the result of ´my_colour´
In that example it reads
conditions, but it should becondition. Did you check that?This example works for me:
With
my_colourbeing:Thank you for your reply! I solved the problem doing this: I defined my colors for the columns bar, and then, I created the list with ´condition´:
and now it's working!
Glad to know it worked out in the end!
Indeed, the names of the elements of the list (element
my_colour$conditionin this example) must match the columns of your annotationdf(columndf$condition). And the names of the vector of colors within each element in the list (CD4T_KO_NSCD4T_KO_STIMin this example) must match the levels in the column of the annotation indf$condition.If you had more than 1 column in the
df, you could build a list with more elements and have multiple annotations!