Formatting tip labels with different fonts

3,276 views
Skip to first unread message

Frederik Bak

unread,
Jun 16, 2017, 6:01:27 AM6/16/17
to ggtree
Hi, 

I am trying to plot a tree where some of the tip labels are supposed to be bold and some are to be italic. 

I have read this: https://guangchuangyu.github.io/ggtree/faq/#formatting-tip-labels but it is still a bit unclear to me. 

I have thought about two ways to do it. One is: 

ggtree(phyloseqobject)+  geom_tiplab(aes(label=Name), align = TRUE, linetype = 0, offset = 0.04) + geom_text2(aes(label = label, fontface = "italic", subset=node %in% Mylist))+geom_text2(aes(label=label, fontface = "bold", subset = node %in% Mylist2))

Obviously, this plots the label names twice. I could off course skip the geom_tiplab part, but I really like the alignment which is made here. 


Another way could be something like:
I have not included the bold part in this one, but I assume it would just be adding another "+geom_tiplab(xxx)" afterwards?

ggtree(phyloseqobject) +  geom_tiplab(aes(subset = node %in% Mylist),label=substitute(italic(x),list(x=c(1:20)[1])), parse=T, align = TRUE, linetype = 0, offset = 0.04)

Here I get this error:

Warning: Ignoring unknown parameters: label, parse
Error: Aesthetics must be either length 1 or the same as the data (20): label, hjust

Mylist has the length 20 which is why I wrote c(1:20) (could has well been a vector with 20 labels). I do not know why this error occurs.

I think the latter option is the preferable one, in order to keep the alignment, but I need to be able to overcome the error.

Frederik


Yu, Guangchuang

unread,
Jun 19, 2017, 12:15:39 AM6/19/17
to Frederik Bak, ggtree



--
G Yu, DK Smith, H Zhu, Y Guan, TTY Lam*. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data, Methods in Ecology and Evolution, 2017, 8(1):28-36. doi:10.1111/2041-210X.12628
 
Homepage: https://guangchuangyu.github.io/ggtree
---
You received this message because you are subscribed to the Google Groups "ggtree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bioc-ggtree+unsubscribe@googlegroups.com.
To post to this group, send email to bioc-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/cc725508-67ab-4e43-84b0-04718328a6b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
--~--~---------~--~----~------------~-------~--~----~
Guangchuang Yu, PhD Candidate
State Key Laboratory of Emerging Infectious Diseases
School of Public Health
The University of Hong Kong
Hong Kong SAR, China
-~----------~----~----~----~------~----~------~--~---

taua...@gmail.com

unread,
Sep 12, 2018, 6:01:43 PM9/12/18
to ggtree
Dear Guangchuang,

How can you use font face in italic and bold at the same time?

Thanks!


On Monday, June 19, 2017 at 12:15:39 AM UTC-4, Yu, Guangchuang wrote:



On Fri, Jun 16, 2017 at 6:01 PM, Frederik Bak <fba...@gmail.com> wrote:
Hi, 

I am trying to plot a tree where some of the tip labels are supposed to be bold and some are to be italic. 

I have read this: https://guangchuangyu.github.io/ggtree/faq/#formatting-tip-labels but it is still a bit unclear to me. 

I have thought about two ways to do it. One is: 

ggtree(phyloseqobject)+  geom_tiplab(aes(label=Name), align = TRUE, linetype = 0, offset = 0.04) + geom_text2(aes(label = label, fontface = "italic", subset=node %in% Mylist))+geom_text2(aes(label=label, fontface = "bold", subset = node %in% Mylist2))

Obviously, this plots the label names twice. I could off course skip the geom_tiplab part, but I really like the alignment which is made here. 


Another way could be something like:
I have not included the bold part in this one, but I assume it would just be adding another "+geom_tiplab(xxx)" afterwards?

ggtree(phyloseqobject) +  geom_tiplab(aes(subset = node %in% Mylist),label=substitute(italic(x),list(x=c(1:20)[1])), parse=T, align = TRUE, linetype = 0, offset = 0.04)

Here I get this error:

Warning: Ignoring unknown parameters: label, parse
Error: Aesthetics must be either length 1 or the same as the data (20): label, hjust

Mylist has the length 20 which is why I wrote c(1:20) (could has well been a vector with 20 labels). I do not know why this error occurs.

I think the latter option is the preferable one, in order to keep the alignment, but I need to be able to overcome the error.

Frederik


--
G Yu, DK Smith, H Zhu, Y Guan, TTY Lam*. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data, Methods in Ecology and Evolution, 2017, 8(1):28-36. doi:10.1111/2041-210X.12628
 
Homepage: https://guangchuangyu.github.io/ggtree
---
You received this message because you are subscribed to the Google Groups "ggtree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bioc-ggtree...@googlegroups.com.

To post to this group, send email to bioc-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/cc725508-67ab-4e43-84b0-04718328a6b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yu, Guangchuang

unread,
Sep 12, 2018, 8:51:48 PM9/12/18
to taua...@gmail.com, ggtree

pls try fontface='bold.italic'.



---
You received this message because you are subscribed to the Google Groups "ggtree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bioc-ggtree+unsubscribe@googlegroups.com.

To post to this group, send email to bioc-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
--~--~---------~--~----~------------~-------~--~----~
Guangchuang Yu PhD
Professor
School of Basic Medical Sciences
Southern Medical University
Guangzhou, China
-~----------~----~----~----~------~----~------~--~---

Tauana Junqueira da Cunha

unread,
Sep 13, 2018, 10:19:53 PM9/13/18
to Yu, Guangchuang, ggtree
Perfect, thanks!
Reply all
Reply to author
Forward
0 new messages