Browse code

support passing `aes(subset)` in geom_nodepoint

guangchuang yu authored on 26/01/2018 04:50:30
Showing 2 changed files

... ...
@@ -1,5 +1,6 @@
1 1
 # ggtree 1.11.5
2 2
 
3
++ support passing `aes(subset)` in geom_nodepoint (2018-01-26, Fri)
3 4
 + fine tune y position after flip; flip compatible with collapse
4 5
     - <https://groups.google.com/d/msgid/bioc-ggtree/1d06342c-9645-4f71-9e66-7d7a7099bf0b%40googlegroups.com?utm_medium=email&utm_source=footer>
5 6
 
... ...
@@ -46,16 +46,19 @@ geom_tippoint <- function(mapping = NULL, data = NULL,
46 46
 ##' @title geom_nodepoint
47 47
 ##' @inheritParams geom_point2
48 48
 ##' @return node point layer
49
+##' @importFrom ggplot2 aes_string
49 50
 ##' @export
50 51
 ##' @author Guangchuang Yu
51 52
 geom_nodepoint <- function(mapping = NULL, data = NULL,
52 53
                        position = "identity", na.rm = FALSE,
53 54
                        show.legend = NA, inherit.aes = TRUE, ...) {
54
-    node <- isTip <- NULL
55
-    self_mapping <- aes(node = node, subset = !isTip)
55
+    self_mapping <- aes_(node = ~node, subset = ~ (!isTip))
56 56
     if (is.null(mapping)) {
57 57
         mapping <- self_mapping
58 58
     } else {
59
+        if (!is.null(mapping$subset)) {
60
+            self_mapping <- aes_string(node = "node", subset = paste0(as.expression(mapping$subset), '&!isTip'))
61
+        }
59 62
         mapping %<>% modifyList(self_mapping)
60 63
     }
61 64
     geom_point2(mapping, data, position, na.rm, show.legend, inherit.aes, stat = StatTreeData, ...)