ggtree
ggtree copied to clipboard
geom_hilight
Prerequisites
- [ ] Have you read Feedback and follow the guide?
- [ ] make sure your are using the latest release version
- [ ] read the documents
- [ ] google your question/issue
Describe you issue
- [ ] Make a reproducible example (e.g. 1)
- [ ] your code should contain comments to describe the problem (e.g. what expected and actually happened?)
Ask in right place
- [ ] for bugs or feature requests, post here (github issue)
- [ ] for questions, please post to google group
Ideally geom-hilights should automatically be placed behind all tree features by default.
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()
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.
you can use to.bottom argument to do this.
library(ggtree)
library(ggplot2)
nwk <- system.file("extdata", "sample.nwk", package="treeio")
tree <- read.tree(nwk)
d <- data.frame(17, 21), type=c("A", "B"))
ggtree(tree) +
geom_hilight(
data = d,
mapping = aes(node = node, fill = type),
type = 'roundrect',
alpha=1,
to.bottom=T
)