I have 2 trees with unequal number of nodes and I want put them together with their tippoints colored according to their taxa. But I am unable to have the same color palette for both the trees, I essentially am looking for a shared legend for the two trees.

I am plotting the tree using the following command:

df = data.frame(read.csv("data.csv"))
A = ape::read.tree(file = "A.treefile")
A2 = ggtree(A, aes(), size=0.1) %<+% df + geom_tippoint(aes(color=taxa), size=2.5)
B = ape::read.tree(file = "B.treefile")
B2 = ggtree(B, aes(), size=0.1) %<+% df + geom_tippoint(aes(color=taxa), size=2.5)

And I have made the mapping of the colors and the unique taxa as follows:

count = length(unique(df$taxa))
palette = distinctColorPalette(count)
names(palette) = unique(df$taxa)

I have tried using palette as input for the color aspect in geom_tippoint and also tried scale_fill_manual(values = palette) with the ggtree, but that also doesn't work. Please let me know how this can be done.

0

There are 0 best solutions below