itol style + color label issue

66 views
Skip to first unread message

Marine Bergot

unread,
Apr 4, 2023, 1:17:50 PM4/4/23
to ggtree

hi, based on previous post i tried to reproduce some itol style. It's working but i can't add color label.
I tried this code:

library(ape)
library(ggtree)                                                                                                                                                                                         library(ggstar)
library(ggtreeExtra)
library(ggplot2)
library(ggstar)



newick_tree <- read.tree("/home/marine/Bureau/CEA/microtrait/Bdello_rooted.nwk")
dat1 <- read.csv("/home/marine/Bureau/CEA/melt_data.csv")
p <- ggtree(newick_tree) %<+% dat1
p1 <- p + theme(legend.position='none') + geom_tiplab(align=TRUE, linetype='dashed', linesize=.3, size=2, geom='label', aes(color=color), label.size=0)


gf1 <- geom_fruit(
           data=dat1,
           geom=geom_star,
           mapping=aes(x=sample, y=id, color=group),
           starshape=15,
           pwidth=0.03,
   offset = 0.15
           )

gf2 <- geom_fruit(
           data=dat1 ,
           geom=geom_star,
           mapping=aes(x=sample, y=id, fill=subgroup),
           starstroke=0,
           starshape = 15,
           pwidth=0.03,
           axis.params = list(axis="x", text.size=1.5, vjust=0, line.size=0,text.angle=-90, hjust=-.2 ),
           offset = 0.15
       )

linecolor <- scale_color_manual(values=c("#FFCC33", "#66CCFF"))
fillcolor <- scale_fill_manual(values=c("#FFCC33", "#66CCFF"), na.translate = FALSE)

fg <- geom_fruit_list(gf2, gf1, linecolor, fillcolor)
p2 <- p1 + fg + scale_y_continuous(limits=c(-1, NA))

pdf("test_ggtree.pdf",  width = 20, height = 10, pointsize = 10)
flip(p2, 194, 142) %>% flip(225, 195) %>% flip(119,226)
dev.off()

but i get this error:

Don't know how to automatically pick scale for object of type <function>. Defaulting to continuous.
Error in `compute_aesthetics()`:
! Aesthetics are not valid data columns.
✖ The following aesthetics are invalid:
✖ `x = sample`
ℹ Did you mistype the name of a data column or forget to add `after_stat()`?
Run `rlang::last_trace()` to see where the error occurred.
Message d'avis :
The following column names/name: group, sample, subgroup, color are/is
the same to tree data, the tree data column names are : label, y,
angle, group, sample, subgroup, color.

ideally i would like to add color by group (like with groupClade) is it possible? i tried but i failed too
tree2 <- groupClade(newick_tree, 225)

thanks :)

Bryan Tegomoh

unread,
Apr 6, 2023, 5:09:18 PM4/6/23
to ggtree
could you provide access to the newick file and melt csv? 
Reply all
Reply to author
Forward
0 new messages