Browse code

introduce to.bottom in geom_hilight

xiangpin authored on 22/04/2022 04:10:04
Showing4 changed files

... ...
@@ -42,6 +42,7 @@ Suggests:
42 42
     emojifont,
43 43
     ggimage,
44 44
     ggplotify,
45
+    shadowtext,
45 46
     grDevices,
46 47
     knitr,
47 48
     prettydoc,
... ...
@@ -13,6 +13,8 @@
13 13
 #' unrooted and daylight layout tree use will use encircle layer. You can specify this parameter to
14 14
 #' `rect` (rectangular layer) or `encircle` (encircle layer), 'gradient' (gradient color), 
15 15
 #' 'roundrect' (round rectangular layer).
16
+#' @param to.bottom logical, whether set the high light layer to the bottom in all layers of 'ggtree'
17
+#' object, default is FALSE.
16 18
 #' @param ... additional parameters, see also the below and Aesthetics section.
17 19
 #'     \itemize{
18 20
 #'        \item \code{align} control the align direction of the edge of high light rectangular.
... ...
@@ -82,12 +84,14 @@ geom_hilight <- function(data=NULL,
82 84
                          mapping=NULL,
83 85
                          node=NULL,
84 86
                          type="auto",
87
+                         to.bottom=FALSE,
85 88
                           ...){
86 89
     params <- list(...)
87 90
     structure(list(data    = data,
88 91
                    mapping = mapping,
89 92
                    node    = node,
90 93
                    type    = type,
94
+                   to.bottom = to.bottom,
91 95
                    params  = params),
92 96
               class = 'hilight')
93 97
 }
... ...
@@ -532,7 +532,12 @@ ggplot_add.hilight <- function(object, plot, object_name){
532 532
                      roundrect = choose_hilight_layer(object = object, type = "roundrect")	 
533 533
                   )
534 534
     }
535
-    ggplot_add(ly, plot, object_name) 
535
+    plot <- ggplot_add(ly, plot, object_name)
536
+    if (object$to.bottom){
537
+        idx <- length(plot$layers)
538
+        plot$layers <- c(plot$layers[idx], plot$layers[-idx])
539
+    }
540
+    plot    
536 541
 }
537 542
 
538 543
 
... ...
@@ -5,9 +5,23 @@
5 5
 \alias{geom_highlight}
6 6
 \title{geom_hilight}
7 7
 \usage{
8
-geom_hilight(data = NULL, mapping = NULL, node = NULL, type = "auto", ...)
8
+geom_hilight(
9
+  data = NULL,
10
+  mapping = NULL,
11
+  node = NULL,
12
+  type = "auto",
13
+  to.bottom = FALSE,
14
+  ...
15
+)
9 16
 
10
-geom_highlight(data = NULL, mapping = NULL, node = NULL, type = "auto", ...)
17
+geom_highlight(
18
+  data = NULL,
19
+  mapping = NULL,
20
+  node = NULL,
21
+  type = "auto",
22
+  to.bottom = FALSE,
23
+  ...
24
+)
11 25
 }
12 26
 \arguments{
13 27
 \item{data}{data.frame, The data to be displayed in this layer, defaults to NULL.}
... ...
@@ -22,6 +36,9 @@ unrooted and daylight layout tree use will use encircle layer. You can specify t
22 36
 \code{rect} (rectangular layer) or \code{encircle} (encircle layer), 'gradient' (gradient color),
23 37
 'roundrect' (round rectangular layer).}
24 38
 
39
+\item{to.bottom}{logical, whether set the high light layer to the bottom in all layers of 'ggtree'
40
+object, default is FALSE.}
41
+
25 42
 \item{...}{additional parameters, see also the below and Aesthetics section.
26 43
 \itemize{
27 44
 \item \code{align} control the align direction of the edge of high light rectangular.