r - 如何在 ggtree 的 `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())
or + scale_fill_discrete()
,但无济于事。
如何将图例添加到 Trait facet?(而且,延伸到任何其他方面?)
解决方案
推荐阅读
- java - java中正则表达式反向组为空时的字符串替换
- c# - 如何向问题发布注释并关闭此问题
- wordpress - 从托管在 Microsoft Azure 上的 WordPress 发送电子邮件
- kql - 操作 ID 的 Kusto 内存状态
- php - docker内部的php soap服务器不返回响应
- msp430 - Ghidra 和 MSP430 反编译器不显示任何功能
- ansible - Ansible win_lineinfile 如何附加到行
- java - 无法从 SharedPreferences 中获取价值
- php - 是否可以在单击时刷新选项卡 - 引导选项卡
- c# - 寻找布尔语句的解释