YuLab-SMU / ggtree

:christmas_tree:Visualization and annotation of phylogenetic trees
https://yulab-smu.top/contribution-tree-data/
838 stars 173 forks source link

geom_hilight #621

Open drdna opened 3 months ago

drdna commented 3 months ago

Prerequisites

Describe you issue

Ask in right place

drdna commented 3 months ago

Ideally geom-hilights should automatically be placed behind all tree features by default.

brj1 commented 3 months ago

You can put the hilight geoms behind the tree by adding the hilight geom first and then the tree geom.

# example tree and data
nwk <- system.file("extdata", "sample.nwk", package="treeio")
tree <- read.tree(nwk)
d <- data.frame(17, 21), type=c("A", "B"))

# geom_hilight last
ggtree(tree) + geom_hilight(data=d, aes(node=node, fill=type),
                            type = "roundrect", alpha = 1)

# geom_hilight first
ggplot(tree) + geom_hilight(data=d, aes(node=node, fill=type),
                            type = "roundrect", alpha = 1) + geom_tree() + theme_tree()
drdna commented 3 months ago

Thanks Brad, that’s what I did to solve the issue. However, it seems to me that a geom_hilight call (if possible) ought to put the feature in the background by default. In my experience, calling ggtree with no arguments is problematic because many of its arguments don’t work in geom_tree. For example, layout doesn't appear to work in geom_tree, so I am unable to generate anything but a rectangular tree using this workaround.