0

I want to plot a phylogenetic tree where

  • tips are colored according to a specific variable
  • branches are colored based on the average colors of the tips (or branches) below

The idea is that if two tips have a blue and a red color, the branch starting from the node connecting them would be purple.

Here is a reproducible example:

# library("BiocManager") # ggtree is stored on Bioconductor
# install("ggtree")
library("ggtree") # phylogenetic tree visualization
library("TDbook") # example dataset
library("ggplot2") # plots

# Loading the example dataset
data("tree_boots")
data("df_tip_data")

# Plot
ggtree(tree_boots, aes(color = mass_in_kg)) %<+% df_tip_data +
  geom_tiplab(show.legend = FALSE) +
  scale_color_viridis_c(na.value = "black")

leading to that figure where branches are black enter image description here

Edit
I found a way using phytools package but it only works for rooted and binary trees. Since the phylogenetic tree I am using has polytomies, I cannot use this solution but I post it for the record:

library("phytools")
mass_tip <- df_tip_data$mass_in_kg
names(mass_tip) <- df_tip_data$Newick_label

plotBranchbyTrait(tree = tree_boots, x = mass_tip,  mode = "tips",
                  type = "fan")

leading to this Figure: enter image description here

P. Denelle
  • 790
  • 10
  • 24

0 Answers0