![](/img/trans.png)
[英]ggtree::facet_plot - Second panel uses xlim parameter from first one
[英]How do I add a legend to a facet in ggtree's `facet_plot`?
我正在使用facet_plot()
在樹尖旁邊添加一個帶有特征值的條形圖。 我需要有一個條形圖的圖例,但在文檔或類似的問題中找不到如何做到這一點。 似乎facet_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")
我嘗試添加+ guides(fill = guide_legend())
或+ scale_fill_discrete()
,但無濟於事。
如何向 Trait 方面添加圖例? (並且,擴展到任何其他方面?)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.