How do I generate a color-coded tanglegram? I want to compare two phylogenies and colour the association lines based on some metadata I have. I have been using ape cophyloplot but I have not had any success in getting the lines to colour accurately according to my data (see previous question).

Note that in my actual work flow I define the colour scheme using a palette to control the colour outcome.

I want a means to make a tangle using phylogenies which I can format. Preferably in R. I like to get an output like this:
I think you can try dendextend, in this manual there is an example of coloring the branches. I don't think it is exactly like your coloring, but with a little tweaking you might get your colorscheme in there.

The manual mentions an argument called color_lines for the function  tanglegram():

# The `which` parameter allows us to pick the elements in the list to compare
iris_dendlist %&gt;% dendlist(which = c(1,4)) %&gt;% ladderize %&gt;% 
   # untangle(method = "step1side", k_seq = 3:20) %&gt;%
   set("rank_branches") %&gt;%
   tanglegram(common_subtrees_color_branches = TRUE)


According to the manual, the code above produces an image like this:



Try to see if you can fit your color palette in there.