The function add_outgroup_to_phylogeny adds an outgroup to a phylogeny.

First, create and plot a phylogeny

library(ape)
library(ribir)

phylogeny <- ape::read.tree(
  text = paste0(
    "(t2:2.286187509,(t5:0.3145724408,",
    "((t1:0.08394513325,t4:0.08394513325):",
    "0.1558558349,t3:0.2398009682):0.07477147256):",
    "1.971615069);"
  )
)
plot(phylogeny)

Here we add an outgroup directly to the crown:

new_phylogeny_1 <- add_outgroup_to_phylogeny(phylogeny, stem_length = 0.0)
plot(new_phylogeny_1)

Here we add an outgroup before the crown:

n_taxa <- length(phylogeny$tip.label)
crown_age <- dist.nodes(phylogeny)[n_taxa + 1][1]
new_phylogeny_2 <- add_outgroup_to_phylogeny(phylogeny, stem_length = crown_age)
plot(new_phylogeny_2)

Plotting both:

plot(phylogeny, main = "add_outgroup_to_phylogeny")
add.scale.bar(x = 0, y = 5)
plot(new_phylogeny_1)
add.scale.bar(x = 0, y = 6)
plot(new_phylogeny_2)
add.scale.bar(x = 0, y = 6)
par(mfrow = c(1, 1))


richelbilderbeek/ribir documentation built on March 19, 2021, 3:55 a.m.