简体   繁体   中英

ggtree issue with coloring both tips and branches

I'm trying to make a plot using ggtree - but I'm having some issues when I try to have both the tip points and branches colored. The tree works with both of these independently, but when I try them together the fill for the nodes is overrided by the color argument from the branch and they come out grey (or it's ignoring it all together and defaulting to the same NA color?).

Here's the minimum code needed to produce the issue:

p <- ggtree(rerooted_tree, aes(color = support))
p <- p %<+% my_DF + 
  geom_tippoint(aes(fill = as.factor(domains.present)))
p

在此处输入图像描述

The variable domains.present is a character column in the dataframe, and works perfectly if it's color instead of fill like in the code below. In the above code, though, if domains.present isn't written as.factor within aes I get an error message saying Continuous value supplied to discrete scale .

q <- ggtree(rerooted_tree)
q <- q %<+% All.my_DF + 
  geom_tippoint(aes(color = domains.present), size = 1)
q

在此处输入图像描述

I'm hoping this is just a syntax issue, but I'm working on getting a reprex together to add if needed. This is a very similar issue to this post , but the OP there solved it without ggtree (I'd rather keep it simple if possible). Thank you in advance!

I ran into the same issue recently and having the branch colour defined outside of aes() worked for me:

p <- ggtree(rerooted_tree, color = support)
p <- p %<+% my_DF + 
  geom_tippoint(aes(fill = as.factor(domains.present)))
p

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM