Browse code

geom_tiplab2 works with mapping = aes(subset) defined by users

guangchuang yu authored on 24/02/2018 11:46:26
Showing2 changed files

... ...
@@ -1,5 +1,7 @@
1 1
 # ggtree 1.11.5
2 2
 
3
++ geom_tiplab2 works with mapping = aes(subset) defined by users  (2018-02-24, Sta)
4
+    - <https://groups.google.com/d/msgid/bioc-ggtree/72e18c5b-0ce5-4c25-80fa-3e2dabda8f72%40googlegroups.com>
3 5
 + fixed overlapping branch after `flip`
4 6
     - <https://github.com/GuangchuangYu/ggtree/issues/167>
5 7
 
... ...
@@ -85,15 +85,17 @@ geom_tiplab <- function(mapping=NULL, hjust = 0,  align = FALSE, linetype = "dot
85 85
 ##' @author Guangchuang Yu
86 86
 ##' @references \url{https://groups.google.com/forum/#!topic/bioc-ggtree/o35PV3iHO-0}
87 87
 geom_tiplab2 <- function(mapping=NULL, hjust=0, ...) {
88
-
89 88
     angle <- isTip <- node <- NULL
90
-
91
-    ## m1 <- aes(subset=(abs(angle) < 90), angle=angle)
92
-    ## m2 <- aes(subset=(abs(angle) >= 90), angle=angle+180)
93 89
     m1 <- aes(subset=(isTip & (angle < 90 | angle > 270)), angle=angle, node = node)
94 90
     m2 <- aes(subset=(isTip & (angle >= 90 & angle <=270)), angle=angle+180, node = node)
95 91
 
96 92
     if (!is.null(mapping)) {
93
+        if (!is.null(mapping$subset)) {
94
+            m1 <- aes_string(angle = "angle", node = "node",
95
+                             subset = paste0(as.expression(mapping$subset), '& (isTip & (angle < 90 | angle > 270))'))
96
+            m2 <- aes_string(angle = "angle+180", node = "node",
97
+                             subset = paste0(as.expression(mapping$subset), '& (isTip & (angle >= 90 & angle <= 270))'))
98
+        }
97 99
         m1 <- modifyList(mapping, m1)
98 100
         m2 <- modifyList(mapping, m2)
99 101
     }