如何在ggtree';s'facet_plot`?

如何在ggtree';s'facet_plot`?,r,ggplot2,ggtree,R,Ggplot2,Ggtree,我正在使用facet\u plot()在我的树的顶端添加一个带有特征值的条形图。我需要有一个barplot的传说,但无法在中找到或如何做到这一点。似乎facet\u plot()让这个问题变得有点棘手 这是我的密码: library(ggtree) library(tidyverse) library(ggstance) # for horizontal versions of geoms # create some random tree and trait data tree <-

我正在使用
facet\u plot()
在我的树的顶端添加一个带有特征值的条形图。我需要有一个barplot的传说,但无法在中找到或如何做到这一点。似乎
facet\u plot()
让这个问题变得有点棘手

这是我的密码:

library(ggtree)
library(tidyverse)
library(ggstance) # for horizontal versions of geoms

# create some random tree and trait data
tree <- rtree(5)
traits <- tibble(
  node  = paste0("t", rep(1:5, 4)),
  trait = rep(LETTERS[1:4], 5),
  value = rnorm(n = 20, mean = 10, sd = 2))

# tree plot with barplot facet
treeplot <- ggtree(tree) + geom_tiplab(align = T)
facet_plot(treeplot,
           panel = "Trait",
           data = traits,
           geom = geom_barh,
           mapping = aes(x = value, fill = trait),
           stat = "identity")
库(ggtree)
图书馆(tidyverse)
库(GGSTANTE)#用于geoms的水平版本
#创建一些随机树和特征数据
树我们可以添加
主题(legend.position=“bottom”)
以获得所需的绘图

facet_plot(treeplot,
           panel = "Trait",
           data = traits,
           geom = geom_barh,
           mapping = aes(x = value, fill = trait),
           stat = "identity", show.legend = TRUE) +
  theme(legend.position = "bottom")