1

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?

mpe
  • 1,000
  • 1
  • 8
  • 25

1 Answers1

1

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.

teofil
  • 2,344
  • 1
  • 8
  • 17
  • This gives me exactly the same result. – mpe Sep 25 '19 at 12:57
  • Sorry, I missed that point in the question. See my edit. You should be able to treat the edge width as any other aesthetic and control the size of symbols through `scale_size_continuous`. – teofil Sep 25 '19 at 15:55
  • Thank you, that works! Somehow I had not thought of just using `scale_size_continuous`. – mpe Sep 26 '19 at 11:25