r - 如何在ggtree的系统发育树中的同一标签中同时应用斜体和普通字体

标签 r ggplot2 ggtree ggtext

我想要斜体的 A 和正常的 CBS。
我认为 ggtext 可能有用,但我遇到了错误。
这是一个例子:

tree<-read.tree(text="(A,(B,C));")
labs=c("*A*CBS","B","C")
tree$tip.label<-labs
ggtree(tree)+ geom_tiplab(align=T) + geom_richtext()

error: geom_rich_text requires the following missing aesthetics: label
我也试过
ggtree(tree)+ aes(label=labs)+geom_tiplab(align=T) + geom_richtext()
error: Aesthetics must be either length 1 or the same as the data (5): label
但我需要的富文本在三个提示标签中,而不是所有五个标签(提示和节点)
有谁知道如何添加标签美学(作为提示标签)?

最佳答案

您可以使用 parse = T参数结合 mathematical annotation :

library(ggtree)
library(ggtext)
tree<-read.tree(text="(A,(B,C));")
labs=c("paste(italic('A'),'CBS')","B","C")
tree$tip.label<-labs
ggtree(tree)+ geom_tiplab(align=T,parse=T)   
enter image description here

关于r - 如何在ggtree的系统发育树中的同一标签中同时应用斜体和普通字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63788793/

相关文章:

python /R : generate dataframe from XML when not all nodes contain all variables?

r - 将 ggplot 对象转换为 plotly 对象会创建与刻度值重叠的轴标题

r - ggplot2 boxplot中的标签框

r - ggplot2 中的 geom_segment 出现问题

R ggtree : How to label single tree tip with ggtree similar to labeling nodes with geom_cladelabel

r - 将 R 脚本的输出传递给 bash 脚本

r - 在 dplyr 中保存 ggplot?

r - geom_rect 和 NULL

r - ggjoy 方面与 ggtree

r - 如何使用引导值注释 ggtree 对象?