Search code examples
rphylogenyggtree

How can I increase the maximum branch width in ggtree?


I added some traits to the branches of my phylogram and scaled the branch widths to their value:

library(ggtree)
library(tidyverse)

tree <- rtree(3, rooted = T)
trait <- data.frame(node = 1:(length(tree$edge.length)+1),
                    thing = rnorm(n = length(tree$edge.length)+1, mean = 4))

t <- full_join(tree, trait)
ggtree(t, aes(size = thing))

Especially if the trait values have a large range, the branch width needs to be able to reflect that. How can I specify the maximum width of the branches?


Solution

  • Call the trait$thing vector directly when mapping the size aesthetic. Best to make sure trait is ordered by tree$tip.label, although ggtree might be doing some matching internally.

    library(ggtree)
    
    tree <- rtree(3, rooted = T)
    trait <- data.frame(node = 1:(length(tree$edge.length)+1),
                        thing = rnorm(n = length(tree$edge.length)+1, mean = 4))
    
    ggtree(tr = tree, aes(size = trait$thing)) + 
      scale_size_continuous(range = c(0.2, 2))
    

    From ?scale_size_continuous:

    range

    a numeric vector of length 2 that specifies the minimum and maximum size of the plotting symbol after transformation.