grepl does not work inside geom_tiplab2 while working inside geom_tiplab?

218 views
Skip to first unread message

Ales Bucek

unread,
Feb 22, 2018, 2:59:44 AM2/22/18
to ggtree
Hi!
I wan to draw a circular tree with only those tip labels shown which match a "Mqua" pattern. I want to use geom_tiplab2 to nicely orient the tip labels, but grepl apparently does not work and all tip labels are shown instead:
ggtree(tree1_midpointrooted, branch.length="none", layout="circular", aes(angle=angle)) +
+     geom_tiplab2(aes(label=label, subset=(grepl("Mqua",label)==TRUE)), color="green")

On the other side, when I use geom_tiplab, only the labels containing "Mqua" are shown according to my expectation:
ggtree(tree1_midpointrooted, branch.length="none", layout="circular", aes(angle=angle)) +
+     geom_tiplab(aes(label=label, subset=(grepl("Mqua",label)==TRUE)), color="green")


Do you have any hints how to get the nice orientation of labels as in geom_tiplab2() while also using subset and grepl to select particular labels?

Thanks in advance!
Ales

Yu, Guangchuang

unread,
Feb 24, 2018, 6:39:05 AM2/24/18
to ggtree

In github version of ggtree, geom_tiplab2 can work with user define subsetting.

library(ggtree)
set.seed(20180224)
x = rtree(30)
ggtree(x, layout='circular') + 
    geom_tiplab2(aes(subset = node < 15))


--
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/72e18c5b-0ce5-4c25-80fa-3e2dabda8f72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



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

gc...@connect.hku.hk

unread,
Feb 24, 2018, 6:40:21 AM2/24/18
to ggtree

In github version of ggtree, geom_tiplab2 can work with user define subsetting.

library(ggtree)
set.seed(20180224)
x = rtree(30)
ggtree(x, layout='circular') + 
    geom_tiplab2(aes(subset = node < 15))


Ales Bucek

unread,
Mar 2, 2018, 1:47:18 AM3/2/18
to ggtree
Dear Guangchuang,
thanks for your response!
Would you give me an example how to subset tips based on a presence of a substring in their name? (i.e. as in my original example, select tips with names which include "Mqua" string). I apparently did not figure out the syntax. Thanks for any advice!
Ales


On Saturday, February 24, 2018 at 8:39:05 PM UTC+9, Yu, Guangchuang wrote:

In github version of ggtree, geom_tiplab2 can work with user define subsetting.

library(ggtree)
set.seed(20180224)
x = rtree(30)
ggtree(x, layout='circular') + 
    geom_tiplab2(aes(subset = node < 15))

On Thu, Feb 22, 2018 at 3:59 PM, Ales Bucek <bucek...@gmail.com> wrote:
Hi!
I wan to draw a circular tree with only those tip labels shown which match a "Mqua" pattern. I want to use geom_tiplab2 to nicely orient the tip labels, but grepl apparently does not work and all tip labels are shown instead:
ggtree(tree1_midpointrooted, branch.length="none", layout="circular", aes(angle=angle)) +
+     geom_tiplab2(aes(label=label, subset=(grepl("Mqua",label)==TRUE)), color="green")

On the other side, when I use geom_tiplab, only the labels containing "Mqua" are shown according to my expectation:
ggtree(tree1_midpointrooted, branch.length="none", layout="circular", aes(angle=angle)) +
+     geom_tiplab(aes(label=label, subset=(grepl("Mqua",label)==TRUE)), color="green")


Do you have any hints how to get the nice orientation of labels as in geom_tiplab2() while also using subset and grepl to select particular labels?

Thanks in advance!
Ales

--
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/72e18c5b-0ce5-4c25-80fa-3e2dabda8f72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yu, Guangchuang

unread,
Mar 5, 2018, 1:26:50 AM3/5/18
to Ales Bucek, ggtree
aes(subset=(grepl("Mqua",label)))

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.

Ales Bucek

unread,
Mar 5, 2018, 2:50:42 AM3/5/18
to ggtree
Ah, I see. geom_tiplab2 is apparently not working with subset because I do not have the "github" version of ggtree as you suggested above. I tried to install it via
>source("https://bioconductor.org/biocLite.R")
>biocLite("ggtree")
but I get an error while loading the package:
>library(ggtree)
Error: package or namespace load failed for ggtree’:
 
object groupClade is not exported by 'namespace:treeio'
Do you have a suggestion how to solve this?
Thanks!
aes(subset=(grepl("Mqua",label)))

Reply all
Reply to author
Forward
0 new messages