4

I want A in italic, and CBS in normal. I think ggtext might be useful, but I got an error. here is an example:

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

I also tried

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

but the rich text I need is in three tip labels, not all five labels (tip and node) does anyone know how to add the label aesthetics (as tip label)?

Cai Bian
  • 141
  • 1
  • 6
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Sep 08 '20 at 07:11
  • What you want to do would have to be added as a feature to the ggtree package. The `geom_tiplab()` function would need a markdown option. – Claus Wilke Sep 09 '20 at 03:40

1 Answers1

1

You could use the parse = T argument combined with 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

Waldi
  • 39,242
  • 6
  • 30
  • 78