YuLab-SMU / ggtreeExtra

:lemon: Add Geom Layers On Circular Or Other Layout Tree Of “ggtree”
https://doi.org/10.1093/molbev/msab166
GNU General Public License v3.0
87 stars 15 forks source link

Add header (or x-axis label) for each geom_fruit? #7

Closed zhanxw closed 3 years ago

zhanxw commented 3 years ago

Thanks for developing ggTreeExtra. geom_fruit is very handy compared to geom_facet. But I do not know how to add a facet title using geom_fruit.

Below is the code using geom_facet and obtain the facet title mat. I wonder how to draw the same facet title or x-axis label using gemo_fruit.

library(ggtree)

set.seed(123)
tree <- rtree(10)
mat = expand.grid(y = tree$tip.label, x = paste('sm', seq(3), sep = ''))
mat$val = rnorm(nrow(mat))
mat$xval = as.numeric(factor(mat$x))
p <- ggtree(tree)
p
p + geom_facet(data = mat, 
               mapping = aes(x = xval, y = y, fill = val),
               geom = geom_tile,
               panel = "mat")

Figure output

Rplot

xiangpin commented 3 years ago

The latest github version has supported this feature.

library(ggtreeExtra)                                                                                                                                                                                               library(ggtree)
library(ggplot2)

set.seed(123)
tree <- rtree(10)

mat = expand.grid(y = tree$tip.label, type = paste('sm', seq(3), sep = ''))
mat$val <- rnorm(nrow(mat))

mat
p <- ggtree(
            tree
            )
p <- p +
     geom_fruit(
         data = mat,
         geom = geom_tile,
         mapping = aes(y=y, x=type, fill=val),
         axis.params=list(
                         axis="x",
                         title = "mat",
                         text.angle = -45,
                         text.size = 2,
                         line.size = 0,
                         vjust = 0
                     )
     )
p

tree_title

zhanxw commented 3 years ago

Thanks for the new version.

danfulop commented 1 year ago

@zhanxw Does this subplot title still work when you have 2 calls to ggfruit() resulting in 2 side by side subplots?