ggtree icon indicating copy to clipboard operation
ggtree copied to clipboard

geom_hilight

Open drdna opened this issue 1 year ago • 4 comments
trafficstars

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

drdna avatar Jul 09 '24 17:07 drdna

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

drdna avatar Jul 09 '24 17:07 drdna

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()

brj1 avatar Jul 09 '24 21:07 brj1

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.

drdna avatar Jul 09 '24 22:07 drdna

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
)

image

xiangpin avatar Dec 17 '24 09:12 xiangpin