I wanted to have my conditions labelled on the heatmap I am making for DGE. This code:
mat <- assay(rld)[topVarGenes,]
condition = c("black", "orange")
names(condition) = c("Dark", "Light")
ann_colors = list(condition = condition)
pheatmap(mat, color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(24), annotation_colors = ann_colors[1], border_color = "grey60", fontsize = 12, scale = "row")
But, this heatmap doesn't have the conditions labelled above the columns like I wanted. So I tried this code:
annotation <- data.frame(annotation)
pheatmap(mat, annotation = annotation, color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(24), border_color = "grey60", fontsize = 12, scale = "row")
Which almost works, but doesn't use the colors I want to label the conditions (samples 1-3 are "dark" condition and are to be labelled black and samples 4-6 are "light" condition and are to be labelled orange). This graph also includes a funky column label under condition for sample which is redundant and I don't know how to get rid of it. Also, the data.frame(annotation) is an excel sheet I imported of samples and corresponding conditions.
Adding back the annotation_colors to the code:
pheatmap(mat, annotation = annotation, color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(24), annotation_colors = ann_colors, border_color = "grey60", fontsize = 12, scale = "row")
produces this error:
Error in convert_annotations(annotation_col, annotation_colors) :
Factor levels on variable condition do not match with annotation_colors
Lastly, I tried this bit of code I found in a stack overflow post to define annotation, which gets R to use the correct colors, but they are not in the correct order for the conditions because the %% 2==0 causes it to label every other sample as 'light', but I can't think of anything else to do. Here is the code:
annotation <- data.frame(condition = factor(1:6 %% 2==0, labels = c("Dark", "Light")))
Help is greatly appreciated!