Node color - force discrete categories in heat_tree

4 views
Skip to first unread message

Raquel Pereira

unread,
Mar 2, 2025, 5:09:19 PMMar 2
to metacoder
I'm currently trying to have a heat_tree with nodes with a descrete color range

0 = red,
1-100 = grey,
100 - 200 = yellow...

So far I managed this by doing a vector with the colors I need in each node by looking at heat_tree$data.

however, when doing the new heat_tree I find it impossible to layer a personalised with the colors. the function legends does not work.

Raquel Pereira

unread,
Mar 3, 2025, 12:46:31 PMMar 3
to metacoder
Well never mind I found a way.

heat_tree
legend_break = factor(c("0", "1-100", "100-400", "400-500", "500-600", "600-700", "700-800", "800-9000"))
legend_data<-data.frame(order=1:8,legend_break )
heat_tree + geom_point(data = legend_data,
           aes(x = 1, y = 1, color = legend_break),
           shape = 15,   # shape 15 gives a square
           size = 6, alpha = 0,
           show.legend = TRUE) +
scale_color_manual(name = "N of sequences",  # Add legend title here
  values = c("#FF0000",
             "#D3D3D3",
             "#BBDF27",
             "#76CD52",
             "#54C568",
             "#46AB74",
             "#389181",
             "#2A788E")) +
  guides(color = guide_legend(override.aes = list(alpha = 1, shape = 15, size = 7))) +
  theme(legend.position = c(1, 1),
        legend.justification = c(1, 1),
        legend.text = element_text(size = 10),    
        legend.title = element_text(size = 10),
        legend.key.size = unit(0.3, "cm"),        
        legend.spacing = unit(0.2, "cm"))    
Reply all
Reply to author
Forward
0 new messages