0

I've made a heatmap including colors for annotating the rows using the script from here. Currently my script is this:

cols <- colorRampPalette(brewer.pal(9, "Paired"))
mycolors <- cols(length(unique(merged_DE_peaks_cut_annotation_type$V10)))
names(mycolors) <- unique(merged_DE_peaks_cut_annotation_type$V10)
mycolors <- list(mycolors = mycolors)
anno <- as.data.frame(merged_DE_peaks_cut_annotation_type$V10])
rownames(anno) <- rownames(merged_DE_peaks_cut_annotation_type)
colnames(anno) <- "Annotation"
pheatmap(merged_DE_peaks_cut_annotation_type[, c(3:6)],
         color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(100),
         annotation_row = anno,
         annotation_colors = mycolors[1],
         cluster_rows = TRUE,
         cluster_cols = FALSE,
         cellheight = 1,
         cellwidth = 80,
         border_color=NA,
         show_rownames = F,
         main="H3K27me3 log2(RPKM) at promoters of >1.5 FC downreg BA1 genes")

I don't get any errors, but the colours that are generated for row annotations aren't those specified in mycolors. They seem to just be the default option, whether I include annotation_colors = mycolors[1] or not doesn't make a difference to the annotation colours on the plot. mycolors is as follows and the #'s codes change when I alter the palette, so it just seems to not get called properly during the pheatmap plot for some reason.

> mycolors[1]
$mycolors
                           None lncg contained in pcg antisense         bidirectional antisense 
                      "#A6CEE3"                       "#1F78B4"                       "#B2DF8A" 
    lncg contained in pcg sense     head-head overlap antisense     tail-tail overlap antisense 
                      "#33A02C"                       "#FB9A99"                       "#E31A1C" 
                  overlap sense     pcg contained in lncg sense pcg contained in lncg antisense 
                      "#FDBF6F"                       "#FF7F00"                       "#CAB2D6" 

Any help really appreciated, thanks!

sian
  • 77
  • 7
  • this lin ```anno <- as.data.frame(merged_DE_peaks_cut_annotation_type$V10])`` will throw an error. can you check the code is correct – StupidWolf Apr 28 '20 at 14:46
  • 1
    and you need to make sure the names of the annotation colors matches that of the data.frame https://stackoverflow.com/questions/58853068/missing-annotations-and-colors-in-pheatmap/58853446#58853446 – StupidWolf Apr 28 '20 at 14:47
  • Oops didn't realise that, it was a just typo during writing/editing the question, not in my actual script. Thanks for that link, it helped me find the problem with mine! – sian Apr 28 '20 at 16:19

1 Answers1

0

In case anyone comes across the same issue, the code below now works. The name of mycolors list must match the colnames of the df used for the annotation.

anno <- as.data.frame(merged_DE_peaks_cut_annotation_type$V10)
rownames(anno) = rownames(merged_DE_peaks_cut_annotation_type)
colnames(anno) <- "V10"
cols <- colorRampPalette(brewer.pal(9, "Set3"))
mycolors <- cols(length(unique(anno$V10)))
names(mycolors) <- unique(anno$V10)
mycolors <- list(V10 = mycolors)
sian
  • 77
  • 7