【问题标题】:how to apply both italic and normal fonts in the same label in phylogenetic tree in ggtree如何在ggtree的系统发育树的同一标签中应用斜体和普通字体
【发布时间】:2020-12-26 12:54:12
【问题描述】:

我想要斜体的 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

但我需要的富文本在三个提示标签中,而不是所有五个标签(提示和节点) 有谁知道如何添加标签美学(作为提示标签)?

【问题讨论】:

  • 如果您包含一个简单的reproducible example,其中包含可用于测试和验证可能解决方案的示例输入和所需输出,则更容易为您提供帮助。
  • 你想要做的必须作为一个特性添加到 ggtree 包中。 geom_tiplab() 函数需要一个降价选项。

标签: r ggplot2 ggtree ggtext


【解决方案1】:

您可以将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)   

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-23
    • 1970-01-01
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 2022-11-17
    • 2013-05-17
    • 1970-01-01
    相关资源
    最近更新 更多