How do I generate a color-coded tanglegram?
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.