我正在尝试向节点添加范围条,如树数据簿中所描述的。以下是我正在努力实现的目标的一个例子:

注意红色的条子。
下面是应该创建带有红色条的树图像的代码:
library(tidyverse)
library(treeio)
library(ggtree)
# create a tree and add a numeric annotation called 'range'
tree = rtree(3) %>% as.treedata %>% as_tibble %>%
mutate(range=0.1) %>%
as.treedata
# plot the tree and add red bars with geom_bar()
ggtree(tree) + geom_range(range='range', color="red")

但是,生成的地块没有红色条。
要向每个节点添加红色条,我需要做什么?
我使用的是ggtree v2.2.4、treeiov1.12.0和ggplot2 v3.3.2。
发布于 2020-10-07 20:12:53
您只给了range一个值。在链接的示例中,列range是一个列表,其中每一行包含一个最小值和最大值。所以你可能想要这样的东西:
library(tidyverse)
library(treeio)
library(ggtree)
# create a tree and add a numeric annotation called 'range'
tree = rtree(3) %>% as.treedata %>% as_tibble %>%
mutate(number = 1:5,
range = lapply(number, function(x) c(-0.1, 0.1) + x)) %>%
as.treedata
# plot the tree and add red bars with geom_bar()
ggtree(tree) +
geom_range("number", range='range', color="red", size = 3, alpha = 0.3) +
theme_tree2()

https://stackoverflow.com/questions/64250987
复制相似问题