<p><em>Answer from @ram-rs, converted from comment:</em></p>
<p>For the <code>Group</code>, try using it without the <code>anno_simple</code>. Just <code>Top_ha = HeatmapAnnotation(Group=top$Group, &quot;Total Mutation Burden&quot; = ...)</code>, nothing else for <code>Group</code>. See if that generates a legend at all. We can customize later.hing else for Group. See if that generates a legend at all. We can customize later.</p>

CC BY-SA 4.0
2021-05-23T12:42:34.537Z
2021-05-23T12:42:34.537Z
gringer
<p>I have a heat map but top and bottom annotation don't have legend</p>
<pre><code>Top_ha = HeatmapAnnotation(Group = anno_simple(top<span class="math-container">$Group, 
                                               col =structure(hue_pal()(length(unique(top$</span>Group))), 
                                                              names = unique(top<span class="math-container">$Group)),
                                           border = TRUE, 
                                           height = unit(5, "mm")),
                       "Total Mutation Burden"=anno_barplot(clin$</span>TMB, height = unit(15, &quot;mm&quot;), width=unit(30, &quot;mm&quot;),gp = gpar(fill = structure(hue_pal()(length(unique(clin<span class="math-container">$TMB))), 
                                                                                                                                               names = unique(clin$</span>TMB)))))



Bottom_ha = HeatmapAnnotation(Response = anno_simple(clin<span class="math-container">$Response, 
                                                 border = T, 
                                                 col = structure(c("purple4", "grey"), names = c("Responders", "NonResponders")),
                                                 height = unit(5, "mm"),show_),
                          "TP53 Status" = anno_simple(clin$</span>TP53_status, 
                                                          border = TRUE, 
                                                          col = structure(c(&quot;firebrick&quot;, &quot;grey&quot;), names = c(&quot;Mutant&quot;,&quot;Wild type&quot;)),
                                                          height = unit(5, &quot;mm&quot;)))


Right_Anno &lt;- HeatmapAnnotation(Signature = anno_text(right$Signature), which = &quot;row&quot;)

Heatmap(mat,
        bottom_annotation = Bottom_ha,
        top_annotation = Top_ha,
        name = &quot;Exposure&quot;,
        right_annotation = Right_Anno,
        show_row_dend = FALSE,
        show_parent_dend_line = FALSE,
        column_split = c(top$Group),
        column_title = c(&quot;Mutagenic&quot;, &quot;DDR Impaired&quot;, &quot;C&gt;A/T Dominant&quot;),
        col = colorRamp2(c( 0, 0.5), c(&quot;white&quot;, &quot;red&quot;)),
        show_column_names = FALSE)
</code></pre>
<p>As you are seeing Response, group and total mutation burden don't have any legend and annotation</p>
<p>Please can you help me to put legend for annotation?</p>
<p>I have tried <code>annotation_lable</code> but says <code>Error: either provide </code>levels<code>or provide named</code>colors<code>.</code></p>
<p>Also <code>show_annotation_name = TRUE,show_legend = TRUE</code> did not work</p>

<r><heatmap>
Adding legend to Botton and top annotation in complexheatmap
# Adding legend to Botton and top annotation in complexheatmap

(Asked by: username_0 on 2020-08-11)

I have a heat map but top and bottom annotation don't have legend
Top_ha = HeatmapAnnotation(Group = anno_simple(top$Group, 
                                               col =structure(hue_pal()(length(unique(top$Group))), 
                                                              names = unique(top$Group)),
                                           border = TRUE, 
                                           height = unit(5, "mm")),
                       "Total Mutation Burden"=anno_barplot(clin$TMB, height = unit(15, "mm"), width=unit(30, "mm"),gp = gpar(fill = structure(hue_pal()(length(unique(clin$TMB))), 
                                                                                                                                               names = unique(clin$TMB)))))



Bottom_ha = HeatmapAnnotation(Response = anno_simple(clin$Response, 
                                                 border = T, 
                                                 col = structure(c("purple4", "grey"), names = c("Responders", "NonResponders")),
                                                 height = unit(5, "mm"),show_),
                          "TP53 Status" = anno_simple(clin$TP53_status, 
                                                          border = TRUE, 
                                                          col = structure(c("firebrick", "grey"), names = c("Mutant","Wild type")),
                                                          height = unit(5, "mm")))


Right_Anno <- HeatmapAnnotation(Signature = anno_text(right$Signature), which = "row")

Heatmap(mat,
        bottom_annotation = Bottom_ha,
        top_annotation = Top_ha,
        name = "Exposure",
        right_annotation = Right_Anno,
        show_row_dend = FALSE,
        show_parent_dend_line = FALSE,
        column_split = c(top$Group),
        column_title = c("Mutagenic", "DDR Impaired", "C>A/T Dominant"),
        col = colorRamp2(c( 0, 0.5), c("white", "red")),
        show_column_names = FALSE)

As you are seeing Response, group and total mutation burden don't have any legend and annotation
Please can you help me to put legend for annotation?
I have tried annotation_lable but says Error: either provide levelsor provide namedcolors.
Also show_annotation_name = TRUE,show_legend = TRUE did not work

**Tags:** r, heatmap

---

## 1 answers

### Answer by username_1 on 2021-05-23. Score: 1 | Accepted answer

*Answer from @ram-rs, converted from comment:*

For the `Group`, try using it without the `anno_simple`. Just `Top_ha = HeatmapAnnotation(Group=top$Group, "Total Mutation Burden" = ...)`, nothing else for `Group`. See if that generates a legend at all. We can customize later.hing else for Group. See if that generates a legend at all. We can customize later.


---

