Italicize alternate names with geom_tiplab

2,074 views
Skip to first unread message

bena...@gmail.com

unread,
Jul 13, 2017, 7:56:26 PM7/13/17
to ggtree
Hello, am having trouble italicizing the tip labels. The examples in the FAQ are only for a singe tip at a time, and I keep getting error messages when I try and apply it to all the tips.
First I attach a data.frame called names_frame with the column named aligned that holds the alternative names. The following works:

ggtree(tree) %<+% names_frame + geom_tiplab(aes(label=aligned))



But how do I make it italic? If I try the following using the format of https://guangchuangyu.github.io/ggtree/faq/#inherit-aes it does not. I think it is because it cannot read aligned as a object since it is inside quotes, but I do not know how to get around that.

ggtree(tree) %<+% names_frame + geom_tiplab(aes(label='italic(aligned)'), parse=TRUE)




How do I make all the tips in a tree italicized, not just one?

- Thanks

Yu, Guangchuang

unread,
Jul 13, 2017, 10:30:49 PM7/13/17
to bena...@gmail.com, ggtree
see https://guangchuangyu.github.io/ggtree/faq/#formatting-tip-labels and you need to follow the guide and provide a reproducible example if it is not working.

--
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/1cd7d96f-e58e-430f-ab1a-dc748e906fa8%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,
Jul 14, 2017, 9:53:20 AM7/14/17
to ggtree
I am also interested in this.

So an example would be:

ggtree(rtree(30)) + geom_tiplab(label='paste(italic("tip.labels"), "accession number")', parse=T)

This works, but only for customized name and accession number. What if I want to use a data frame that has the tip names and accessions in two columns? I tried giving the name of the column or tip.labels but it doesn't use the objects that have the actual names. If I remove the ' ' around paste, it doesn't find the function italic().

ggtree(rtree(30)) + geom_tiplab(label=paste(italic("tip.labels"), "accession number"), parse=T)

How can we use italics to all the tree@phylo$tip.labels in a tree?

Thanks!



On Thursday, July 13, 2017 at 10:30:49 PM UTC-4, Yu, Guangchuang wrote:
see https://guangchuangyu.github.io/ggtree/faq/#formatting-tip-labels and you need to follow the guide and provide a reproducible example if it is not working.
On Fri, Jul 14, 2017 at 7:56 AM, <bena...@gmail.com> wrote:
Hello, am having trouble italicizing the tip labels. The examples in the FAQ are only for a singe tip at a time, and I keep getting error messages when I try and apply it to all the tips.
First I attach a data.frame called names_frame with the column named aligned that holds the alternative names. The following works:

ggtree(tree) %<+% names_frame + geom_tiplab(aes(label=aligned))



But how do I make it italic? If I try the following using the format of https://guangchuangyu.github.io/ggtree/faq/#inherit-aes it does not. I think it is because it cannot read aligned as a object since it is inside quotes, but I do not know how to get around that.

ggtree(tree) %<+% names_frame + geom_tiplab(aes(label='italic(aligned)'), parse=TRUE)




How do I make all the tips in a tree italicized, not just one?

- Thanks

--
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/1cd7d96f-e58e-430f-ab1a-dc748e906fa8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

bena...@gmail.com

unread,
Jul 14, 2017, 11:07:20 AM7/14/17
to ggtree
Here is a reproducible example. The example you linked to is for a single node, and if I try and copy the syntax it doesn't work for applying to all the tip labels.


library(ggtree)
tree <- rtree(5)
alternate_names <- c("a","b","c","d","e")
name_frame <- data.frame(cbind(tree$tip.label,alternate_names))
treeplot <- ggtree(tree) %<+% name_frame
treeplot + geom_tiplab(aes(label=label))                                                                            #this works
treeplot + geom_tiplab(aes(label=alternate_names))                                                         #this works
treeplot + geom_tiplab(aes(label=paste(label,alternate_names)))                                      #this works
treeplot + geom_tiplab(aes(label=italic(label)))                                                                   #does not work
treeplot + geom_tiplab(aes(label='italic(label)'), parse=TRUE)                                           #prints italic, but does not reference the label
treeplot + geom_tiplab(aes(label='italic(alternate_names)'), parse=TRUE)                        #same as above
treeplot + geom_tiplab(aes(label='paste(italic(label),altername_names)'), parse=TRUE)  #this is the desired function, but does not work

- Thanks



On Thursday, July 13, 2017 at 7:30:49 PM UTC-7, Yu, Guangchuang wrote:
see https://guangchuangyu.github.io/ggtree/faq/#formatting-tip-labels and you need to follow the guide and provide a reproducible example if it is not working.
On Fri, Jul 14, 2017 at 7:56 AM, <bena...@gmail.com> wrote:
Hello, am having trouble italicizing the tip labels. The examples in the FAQ are only for a singe tip at a time, and I keep getting error messages when I try and apply it to all the tips.
First I attach a data.frame called names_frame with the column named aligned that holds the alternative names. The following works:

ggtree(tree) %<+% names_frame + geom_tiplab(aes(label=aligned))



But how do I make it italic? If I try the following using the format of https://guangchuangyu.github.io/ggtree/faq/#inherit-aes it does not. I think it is because it cannot read aligned as a object since it is inside quotes, but I do not know how to get around that.

ggtree(tree) %<+% names_frame + geom_tiplab(aes(label='italic(aligned)'), parse=TRUE)




How do I make all the tips in a tree italicized, not just one?

- Thanks

--
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/1cd7d96f-e58e-430f-ab1a-dc748e906fa8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yu, Guangchuang

unread,
Jul 17, 2017, 3:51:22 AM7/17/17
to bena...@gmail.com, ggtree
treeplot + 
    geom_tiplab(aes(label=paste0('italic(', label, ')~italic(', alternate_names, ')')), 
                parse=TRUE)
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.

taua...@gmail.com

unread,
Jul 17, 2017, 12:25:54 PM7/17/17
to ggtree
Thanks!

ludovic....@gmail.com

unread,
Feb 22, 2021, 7:48:50 PM2/22/21
to ggtree
Hello,

Is there a way of getting this 2017 example to work with fontface? I haven't found a way of applying a different fontface to 'label' and to 'alternate_names'.

All I can get is having the two labels overlapping one another depending on separate geom_tiplab:

p1 + geom_tiplab(align=FALSE , linesize=0, aes(label=label),fontface = 3)+ geom_tiplab(aes(label=alternate_names),fontface = 1)

Thanks.

Reply all
Reply to author
Forward
0 new messages