Browse code

fixed R check for #152

guangchuang yu authored on 12/09/2017 10:01:00
Showing 16 changed files

... ...
@@ -6,5 +6,8 @@ Justin Silverman
6 6
 
7 7
 JustGitting
8 8
 ----------------
9
-+ `Add daylight layout for unrooted trees`
10
-  - <https://github.com/GuangchuangYu/ggtree/pull/124>
11 9
\ No newline at end of file
10
++ Annotation functions (`geom_hilight_encircle` & `geom_cladelabel2`) for
11
+  unrooted layout
12
+  - <https://github.com/GuangchuangYu/ggtree/pull/152>
13
++ Add daylight layout for unrooted trees
14
+  - <https://github.com/GuangchuangYu/ggtree/pull/124>
... ...
@@ -23,6 +23,7 @@ Imports:
23 23
     magrittr,
24 24
     methods,
25 25
     rvcheck,
26
+    scales,
26 27
     tidyr,
27 28
     utils
28 29
 Suggests:
... ...
@@ -33,7 +34,6 @@ Suggests:
33 34
     knitr,
34 35
     prettydoc,
35 36
     rmarkdown,
36
-    scales,
37 37
     testthat
38 38
 VignetteBuilder: knitr
39 39
 ByteCompile: true
... ...
@@ -92,7 +92,6 @@ export(scale_color)
92 92
 export(scale_x_ggtree)
93 93
 export(set_hilight_legend)
94 94
 export(stat_balance)
95
-export(stat_chull)
96 95
 export(stat_hilight)
97 96
 export(subview)
98 97
 export(theme_inset)
... ...
@@ -175,11 +174,14 @@ importFrom(graphics,identify)
175 174
 importFrom(grid,convertX)
176 175
 importFrom(grid,convertY)
177 176
 importFrom(grid,dataViewport)
177
+importFrom(grid,gpar)
178 178
 importFrom(grid,grid.layout)
179 179
 importFrom(grid,grid.locator)
180 180
 importFrom(grid,grid.newpage)
181
+importFrom(grid,grobTree)
181 182
 importFrom(grid,pushViewport)
182 183
 importFrom(grid,rasterGrob)
184
+importFrom(grid,rectGrob)
183 185
 importFrom(grid,unit)
184 186
 importFrom(grid,viewport)
185 187
 importFrom(magrittr,"%<>%")
... ...
@@ -189,6 +191,7 @@ importFrom(magrittr,equals)
189 191
 importFrom(methods,is)
190 192
 importFrom(methods,missingArg)
191 193
 importFrom(rvcheck,get_fun_from_pkg)
194
+importFrom(scales,alpha)
192 195
 importFrom(tidyr,gather)
193 196
 importFrom(treeio,as.phylo)
194 197
 importFrom(treeio,as.treedata)
... ...
@@ -1,5 +1,7 @@
1 1
 CHANGES IN VERSION 1.9.4
2 2
 ------------------------
3
+ o geom_hilight_encircle and geom_cladelabel2 <2017-09-12, Tue>
4
+   + https://github.com/GuangchuangYu/ggtree/pull/152
3 5
  o set_hilight_legend <2017-08-30, Wed>
4 6
  o geom_motif for aligned motif <2017-08-22, Tue>
5 7
    + https://github.com/GuangchuangYu/ggtree/issues/148
6 8
deleted file mode 100644
... ...
@@ -1 +0,0 @@
1
-stat_chull.R
... ...
@@ -1,6 +1,6 @@
1 1
 ##' Find Most Recent Common Ancestor among a vector of tips
2 2
 ##'
3
-##' 
3
+##'
4 4
 ##' @title MRCA
5 5
 ##' @param obj supported tree object or ggplot object
6 6
 ##' @param tip a vector of mode numeric or character specifying the tips
... ...
@@ -41,16 +41,16 @@ getMRCA.df <- function(data, tip) {
41 41
 getMRCA.df_internal <- function(data, tip, anc) {
42 42
     node1 <- which(tip == data$label | tip == data[, "node"])
43 43
     node2 <- which(anc == data$label | anc == data[, "node"])
44
-    
44
+
45 45
     anc1 <- get.ancestor.df(data, node1)
46 46
     anc2 <- get.ancestor.df(data, node2)
47
-    
47
+
48 48
     if(is.null(anc1)){
49 49
       print("Warning getMRCA.df_internal(): tip is root")
50
-    }else if(is.null(anc1)){
50
+    } else if(is.null(anc2)){
51 51
       print("Warning getMRCA.df_internal(): anc is root")
52 52
     }
53
-    
53
+
54 54
     # Return common ancestors.
55 55
     intersect(c(node1, anc1), c(node2, anc2))[1]
56 56
 }
... ...
@@ -7,14 +7,14 @@
7 7
 ##' @param offset offset of bar and text from the clade
8 8
 ##' @param offset.text offset of text from bar
9 9
 ##' @param offset.bar offset of bar from text
10
-##' @param align logical 
10
+##' @param align logical
11 11
 ##' @param barsize size of bar
12 12
 ##' @param fontsize font size of text
13
-##' @param angle angle of text
13
+## @param angle angle of text
14 14
 ##' @param geom one of 'text' or 'label'
15 15
 ##' @param hjust justify text horizontally
16 16
 ##' @param color color for clade & label, of length 1 or 2
17
-##' @param fill fill label background, only work with geom='label'
17
+## @param fill fill label background, only work with geom='label'
18 18
 ##' @param family sans by default, can be any supported font
19 19
 ##' @param parse logical, whether parse label
20 20
 ##' @param ... additional parameter
... ...
@@ -33,23 +33,23 @@ geom_cladelabel2 <- function(node, label, offset=0, offset.text=0, offset.bar=0,
33 33
     na.rm <- TRUE
34 34
     inherit.aes <- FALSE
35 35
 
36
-    
36
+
37 37
     # create custom arguments from ellipsis (aka '...') for stat_cladeText2 depending on geom type
38
-    
39
-    # http://ggplot2.tidyverse.org/reference/geom_text.html 
38
+
39
+    # http://ggplot2.tidyverse.org/reference/geom_text.html
40 40
     # geom_label(mapping = NULL, data = NULL, stat = "identity",
41 41
     #            position = "identity", ..., parse = FALSE, nudge_x = 0, nudge_y = 0,
42 42
     #            label.padding = unit(0.25, "lines"), label.r = unit(0.15, "lines"),
43 43
     #            label.size = 0.25, na.rm = FALSE, show.legend = NA,
44 44
     #            inherit.aes = TRUE)
45
-    # 
45
+    #
46 46
     # geom_text(mapping = NULL, data = NULL, stat = "identity",
47 47
     #           position = "identity", ..., parse = FALSE, nudge_x = 0, nudge_y = 0,
48 48
     #           check_overlap = FALSE, na.rm = FALSE, show.legend = NA,
49 49
     #           inherit.aes = TRUE)
50 50
     #
51 51
     # Aesthetics: x, y, label, alpha, angle, colour, family, fontface, group, hjust, lineheight, size, vjust
52
-    
52
+
53 53
     # http://ggplot2.tidyverse.org/reference/geom_segment.html
54 54
     # geom_curve(mapping = NULL, data = NULL, stat = "identity",
55 55
     #            position = "identity", ..., curvature = 0.5, angle = 90, ncp = 5,
... ...
@@ -57,38 +57,38 @@ geom_cladelabel2 <- function(node, label, offset=0, offset.text=0, offset.bar=0,
57 57
     #            inherit.aes = TRUE)
58 58
     #
59 59
     # Aesthetics:  x, y, xend, yend, alpha, colour, group, linetype, size
60
-    
60
+
61 61
     # name_mapping = list('oldA'='newA', 'oldB'='newB')
62 62
     # data_list = list(oldB=1, oldA=2)
63 63
     # names(data_list) = name_mapping[match(names(data_list), names(name_mapping))]
64
-    
65
-    arg_list_geom_label <- c( "nudge_x", "nudge_y", "label.padding", "label.r", "label.size", 
64
+
65
+    arg_list_geom_label <- c( "nudge_x", "nudge_y", "label.padding", "label.r", "label.size",
66 66
                               "alpha", "angle", "fontface", "group", "lineheight", "size", "vjust", "fill")
67
-    
68
-    arg_list_geom_text <- c( "nudge_x", "nudge_y", "check_overlap", 
67
+
68
+    arg_list_geom_text <- c( "nudge_x", "nudge_y", "check_overlap",
69 69
                              "alpha", "angle", "fontface", "group", "lineheight", "size", "vjust")
70
-    
70
+
71 71
     # ignore angle
72
-    arg_list_geom_curve <- c( "curvature", "ncp", "arrow", "lineend", 
72
+    arg_list_geom_curve <- c( "curvature", "ncp", "arrow", "lineend",
73 73
                               "alpha", "group", "linetype")
74
-    
75
-    
74
+
75
+
76 76
     # Parse ellipsis to collect parameters for geom_text or geom_label
77 77
     ellipsis <- list(...)
78 78
     if (geom == "text") {
79
-      args_stat_cladeText2 <- ellipsis[names(ellipsis) %in% arg_list_geom_text]  
79
+      args_stat_cladeText2 <- ellipsis[names(ellipsis) %in% arg_list_geom_text]
80 80
     } else {
81 81
       args_stat_cladeText2 <- ellipsis[names(ellipsis) %in% arg_list_geom_label]
82 82
     }
83
-    
83
+
84 84
     if (parse == 'emoji') {
85 85
       emoji <- get_fun_from_pkg("emojifont", "emoji")
86 86
       label <- emoji(label)
87 87
       parse <- FALSE
88 88
       family <- "EmojiOne"
89 89
     }
90
-    
91
-    
90
+
91
+
92 92
     # add parameters to stat_cladeText2 options.
93 93
     args_stat_cladeText2$node        <- node
94 94
     args_stat_cladeText2$label       <- label
... ...
@@ -99,16 +99,16 @@ geom_cladelabel2 <- function(node, label, offset=0, offset.text=0, offset.bar=0,
99 99
     args_stat_cladeText2$family      <- family
100 100
     args_stat_cladeText2$mapping     <- mapping
101 101
     args_stat_cladeText2$data        <- data
102
-    args_stat_cladeText2$geom        <- geom 
102
+    args_stat_cladeText2$geom        <- geom
103 103
     args_stat_cladeText2$position    <- position
104 104
     args_stat_cladeText2$show.legend <- show.legend
105
-    args_stat_cladeText2$inherit.aes <- inherit.aes 
105
+    args_stat_cladeText2$inherit.aes <- inherit.aes
106 106
     args_stat_cladeText2$na.rm       <- na.rm
107
-    args_stat_cladeText2$parse       <- parse 
108
-    
107
+    args_stat_cladeText2$parse       <- parse
108
+
109 109
     # create arg list of stat_cladeBar2.
110 110
     args_stat_cladeBar2 <- ellipsis[names(ellipsis) %in% arg_list_geom_curve]
111
-    
111
+
112 112
     args_stat_cladeBar2$size        <- barsize
113 113
     args_stat_cladeBar2$node        <- node
114 114
     args_stat_cladeBar2$offset      <- offset+offset.bar
... ...
@@ -120,8 +120,8 @@ geom_cladelabel2 <- function(node, label, offset=0, offset.text=0, offset.bar=0,
120 120
     args_stat_cladeBar2$show.legend <- show.legend
121 121
     args_stat_cladeBar2$inherit.aes <- inherit.aes
122 122
     args_stat_cladeBar2$na.rm       <- na.rm
123
-    
124
-    
123
+
124
+
125 125
     if (!is.null(color)) {
126 126
         if (length(color) > 2) {
127 127
           stop("color should be of length 1 or 2")
... ...
@@ -136,7 +136,7 @@ geom_cladelabel2 <- function(node, label, offset=0, offset.text=0, offset.bar=0,
136 136
           args_stat_cladeBar2$colour <- color[2]
137 137
         }
138 138
     }
139
-    
139
+
140 140
     # print('text opts') # Debug
141 141
     # print(args_stat_cladeText2) # Debug
142 142
     # print('bar opts') # Debug
... ...
@@ -165,7 +165,7 @@ stat_cladeText2 <- function(mapping=NULL, data=NULL,
165 165
   } else {
166 166
     mapping <- modifyList(mapping, default_aes)
167 167
   }
168
-  
168
+
169 169
   layer(stat=StatCladeText2,
170 170
         data=data,
171 171
         mapping=mapping,
... ...
@@ -181,25 +181,25 @@ stat_cladeText2 <- function(mapping=NULL, data=NULL,
181 181
                     na.rm  = na.rm,
182 182
                     parse  = parse,
183 183
                     ...)
184
-        
184
+
185 185
   )
186
-  
186
+
187 187
 }
188
-      
188
+
189 189
 stat_cladeBar2 <- function(mapping=NULL, data=NULL,
190 190
                            geom="curve", position="identity",
191 191
                            node, offset, align, ...,
192 192
                            show.legend=NA, inherit.aes=FALSE, na.rm=FALSE) {
193 193
   default_aes <- aes_(x=~x, y=~y, node=~node, parent=~parent, xend=~x, yend=~y)
194 194
   if (is.null(mapping)) {
195
-    mapping <- default_aes 
195
+    mapping <- default_aes
196 196
   } else {
197 197
     mapping <- modifyList(mapping, default_aes)
198 198
   }
199
-  
199
+
200 200
   layer(stat=StatCladeBar2,
201 201
         data=data,
202
-        mapping=mapping, 
202
+        mapping=mapping,
203 203
         geom=geom,
204 204
         position=position,
205 205
         show.legend = show.legend,
... ...
@@ -210,12 +210,12 @@ stat_cladeBar2 <- function(mapping=NULL, data=NULL,
210 210
                     align=align,
211 211
                     na.rm=na.rm,
212 212
                     ...)
213
-        
213
+
214 214
   )
215 215
 }
216 216
 
217 217
 StatCladeText2 <- ggproto("StatCladeText2", Stat,
218
-                          
218
+
219 219
                           required_aes = c("x", "y", "label"),
220 220
 
221 221
                           compute_group = function(self, data, scales, params = NULL, node, label, offset, align) {
... ...
@@ -223,8 +223,8 @@ StatCladeText2 <- ggproto("StatCladeText2", Stat,
223 223
 
224 224
                             # computer_group does not need to return df$label as label is declared in the geom_cladelabel2() function.
225 225
                             # The data.frame returned by computer_group() does not override the variables explicitly specified in the geom_cladelabel2()
226
-                            # df$label <- label 
227
-                            
226
+                            # df$label <- label
227
+
228 228
                             if(is.null(params$angle)){
229 229
                               df$angle <- df$theta_label * 180
230 230
                               if( df$angle > 90 & df$angle < 270){
... ...
@@ -232,15 +232,15 @@ StatCladeText2 <- ggproto("StatCladeText2", Stat,
232 232
                                 df$angle <- df$angle + 180
233 233
                               }
234 234
                             }
235
-                          
235
+
236 236
                             return(df)
237 237
                           }
238 238
 )
239 239
 
240 240
 StatCladeBar2 <- ggproto("StatCladeBar2", Stat,
241
-                        
241
+
242 242
                         required_aes = c("x", "y", "xend", "yend"),
243
-                        
243
+
244 244
                         compute_group = function(self, data, scales, params, node, offset, align) {
245 245
                           df <- get_cladelabel2_position_bar(data, node, offset, align, adjustRatio=1.1)
246 246
                           return(df)
... ...
@@ -249,19 +249,19 @@ StatCladeBar2 <- ggproto("StatCladeBar2", Stat,
249 249
 
250 250
 get_cladelabel2_position_label <- function(data, node, offset, align, adjustRatio) {
251 251
   df <- get_cladelabel2_position_(data, node)
252
-  
252
+
253 253
   if (align) {
254 254
     # Find max radius from tree root.
255 255
     r <- max(getNodeEuclDistances(data, getRoot.df(data)))
256 256
   } else {
257 257
     r <- df$r
258 258
   }
259
-  
259
+
260 260
   r <- r * adjustRatio + offset
261
-  
261
+
262 262
   # Calculate the angle between theta_left and theta_right
263 263
   delta <- df$theta_left - df$theta_right
264
-  
264
+
265 265
   if(delta > 0){
266 266
     theta_label <- delta/2 + df$theta_right
267 267
   }else if(delta < 0){
... ...
@@ -270,18 +270,18 @@ get_cladelabel2_position_label <- function(data, node, offset, align, adjustRati
270 270
   }else{
271 271
     theta_label <- df$theta_left
272 272
   }
273
-  
273
+
274 274
   # correct if theta_label > 360
275 275
   if(theta_label > 2){
276
-    theta_label <-  theta_label - 2 
276
+    theta_label <-  theta_label - 2
277 277
   }
278
-  
278
+
279 279
   # Calculate the position of the label
280 280
   x1 <- r*cospi(theta_label) + data[data$node==node, 'x']
281 281
   y1 <- r*sinpi(theta_label) + data[data$node==node, 'y']
282
-  
282
+
283 283
   data.frame(x=x1, y=y1, theta_label=theta_label)
284
-  
284
+
285 285
 }
286 286
 
287 287
 
... ...
@@ -302,8 +302,8 @@ get_cladelabel2_position_bar <- function(data, node, offset, align, adjustRatio)
302 302
   y1 <- r*sinpi(df$theta_right) + data[data$node==node, 'y']
303 303
   xend <- r*cospi(df$theta_left) + data[data$node==node, 'x']
304 304
   yend <- r*sinpi(df$theta_left) + data[data$node==node, 'y']
305
-  
306
-  data.frame(x=x1, y=y1, xend=xend, yend=yend)  
305
+
306
+  data.frame(x=x1, y=y1, xend=xend, yend=yend)
307 307
 
308 308
 }
309 309
 
... ...
@@ -311,11 +311,11 @@ get_cladelabel2_position_bar <- function(data, node, offset, align, adjustRatio)
311 311
 get_cladelabel2_position_ <- function(data, node) {
312 312
   # get left and right angles of the clade subtree.
313 313
   subtree <- list( subtree = getSubtree.df(data, node), node = node )
314
-  
314
+
315 315
   arc <- getTreeArcAngles(data, node, subtree)
316 316
   # get max distance from node to clade tips.
317 317
   r <- max(getNodeEuclDistances(data[data$node %in% subtree$subtree,], node))
318
-  
318
+
319 319
   data.frame(r=r, theta_left=as.numeric(arc['left']), theta_right=as.numeric(arc['right']))
320 320
 }
321 321
 
... ...
@@ -1,14 +1,19 @@
1
-# Encircle code originally from:
2
-# https://github.com/hrbrmstr/ggalt/blob/master/R/geom_encircle.r
1
+## Encircle code originally from:
2
+## https://github.com/hrbrmstr/ggalt/blob/master/R/geom_encircle.r
3 3
 
4
-# draw_key_hack
4
+### draw_key_hack
5
+
6
+##' @importFrom scales alpha
7
+##' @importFrom grid grobTree
8
+##' @importFrom grid rectGrob
9
+##' @importFrom grid gpar
5 10
 draw_key_hack <- function(data, params, size) {
6 11
   print('draw_key_hack') ##DEBUG
7 12
   data$fill <- alpha(data$fill, data$alpha)
8 13
   data$alpha <- 1
9
-  
14
+
10 15
   grobTree(
11
-    if (!is.na(data$fill)) grid::rectGrob(gp = gpar(col = NA, fill = data$fill)),
16
+    if (!is.na(data$fill)) rectGrob(gp = gpar(col = NA, fill = data$fill)),
12 17
     draw_key_path(data, params)
13 18
   )
14 19
 }
... ...
@@ -35,9 +40,9 @@ GeomHilight <- ggproto("GeomHilight", Geom,
35 40
                                          size     = 1,
36 41
                                          s_shape  = 0.5,  ## corresponds to default shape in xspline of -0.5
37 42
                                          s_open   = FALSE),
38
-                       
43
+
39 44
                        draw_key = draw_key_hack, ## ???
40
-                       
45
+
41 46
                        # # Find set of nodes that define the clade.
42 47
                        # setup_params = function(data, params) {
43 48
                        #   print('setup_params()') ## DEBUG
... ...
@@ -45,80 +50,80 @@ GeomHilight <- ggproto("GeomHilight", Geom,
45 50
                        #     # Assume clade subset is given by user via data = data[subset]
46 51
                        #     return(params)
47 52
                        #   }
48
-                       #   
53
+                       #
49 54
                        #   # Find set of child nodes from clade_node.
50 55
                        #   clade_node <- 15
51
-                       #   
56
+                       #
52 57
                        #   #params$clade_root_node <- clade_node
53 58
                        #   params
54 59
                        # },
55
-                       
60
+
56 61
                        draw_group = function(data, panel_scales, coord) {
57 62
                          # Determine if tree is circular or radial as uses Polar coordinates.
58 63
                          #"CoordCartesian" %in% class(coord)
59 64
                          #"CoordPolar" %in% class(coord)
60
-                         
65
+
61 66
                          # Get clade root node and clade node ids.
62 67
                          clade_root_node <- data[1,]$clade_root_node
63
-                         
68
+
64 69
                          # Check if clade parent node exists in data.
65 70
                          if( !(clade_root_node %in% data$node) ){
66 71
                            cat('ERROR: clade node id (',clade_root_node,') not found in tree data.\n')
67 72
                            return(NULL)
68 73
                          }
69
-                         
74
+
70 75
                          clade_ids = ggtree:::getSubtree.df(data, clade_root_node)
71
-                         
76
+
72 77
                          # Remove non-clade rows.
73 78
                          data <- data[data$node %in% clade_ids,]
74
-                         
79
+
75 80
                          # # Get layout
76 81
                          #
77 82
                          # layout <- data[1,]$layout
78
-                         # 
83
+                         #
79 84
                          # If layout is {"rectangular”, “slanted”, “fan”, “circular”, “radial”} then find set of points that define
80 85
                          # the retangular region around the clade.
81 86
                          # if( layout %in% c('rectangular', 'slanted', 'fan', 'circular', 'radial') ){
82
-                         #   
87
+                         #
83 88
                          #   # get number of clade nodes.
84 89
                          #   n <- nrow(data)
85
-                         #   
90
+                         #
86 91
                          #   # Find min and max (x,y) coordinates to find rectangle covering the clade.
87 92
                          #   X <- data$x
88 93
                          #   #Y <- data$y
89
-                         #   
94
+                         #
90 95
                          #   min_x <- min(X)
91 96
                          #   max_x <- max(X)
92 97
                          #   #min_y <- min(Y)
93 98
                          #   #max_y <- max(Y)
94
-                         #   
95
-                         #   
99
+                         #
100
+                         #
96 101
                          #   # Start with single row
97 102
                          #   #data <- data[1,]
98 103
                          #   #data <- data[rep(seq_len(nrow(data)), 4), ]
99 104
                          #   #data$x <- c(max_x, min_x, min_x, max_x)
100 105
                          #   #data$y <- c(min_y, max_y, min_y, max_y)
101
-                         #   
106
+                         #
102 107
                          #   points_right <- data
103 108
                          #   # Update points with bounded box (min and max of X )
104 109
                          #   data$x <- min_x
105 110
                          #   points_right$x <- max_x
106 111
                          #   print('points_right')
107 112
                          #   print(points_right)
108
-                         #   
113
+                         #
109 114
                          #   # Combine left and right extreme points
110 115
                          #   data <- rbind(data, points_right)
111
-                         #   
116
+                         #
112 117
                          #   print('Box data') #DEBUG
113 118
                          #   print(data) #DEBUG
114
-                         #                             
119
+                         #
115 120
                          # }
116
-                         
121
+
117 122
                          # Create glob
118 123
                          glob <- get_glob_encircle(data, panel_scales, coord)
119
-                         
124
+
120 125
                          return(glob)
121
-                         
126
+
122 127
                        }
123 128
 )
124 129
 
... ...
@@ -127,30 +132,30 @@ get_glob_encircle <- function(data, panel_scales, coord){
127 132
   coords <- coord$transform(data, panel_scales)
128 133
   first_row <- coords[1, , drop = FALSE]
129 134
   rownames(first_row) <- NULL ## prevent warning later
130
-  
135
+
131 136
   m <- lapply(coords[,c("x","y")],mean,na.rm=TRUE)
132 137
   ch <- grDevices::chull(coords[c("x","y")])
133
-  
138
+
134 139
   mkcoords <- function(x,y) {
135 140
     data.frame(x,y,first_row[!names(first_row) %in% c("x","y")])
136 141
   }
137
-  
142
+
138 143
   coords <- coords[ch,]
139 144
   ## FIXME: using grid:: a lot. importFrom instead?
140
-  
145
+
141 146
   ## convert from lengths to physical units, for computing *directions*
142 147
   cc <- function(x,dir="x")
143 148
     grid::convertUnit(grid::unit(x,"native"),"mm",typeFrom="dimension",
144 149
                       axisFrom=dir,valueOnly=TRUE)
145
-  
150
+
146 151
   ## convert back to native (e.g. native + snpc offset)
147 152
   cc_inv <- function(x,dir="x")
148 153
     grid::convertUnit(x,"native",typeFrom="location",
149 154
                       axisFrom=dir,valueOnly=TRUE)
150
-  
155
+
151 156
   cc_comb <- function(x1,x2,dir="x")
152 157
     cc_inv(unit(x1,"native")+unit(x2,"snpc"),dir=dir)
153
-  
158
+
154 159
   ## find normalized vector: d1 and d2 have $x, $y elements
155 160
   normFun <- function(d1,d2) {
156 161
     dx <- cc(d1$x-d2$x)
... ...
@@ -158,7 +163,7 @@ get_glob_encircle <- function(data, panel_scales, coord){
158 163
     r <- sqrt(dx*dx+dy*dy)
159 164
     list(x=dx/r,y=dy/r)
160 165
   }
161
-  
166
+
162 167
   if (nrow(coords)==1) {
163 168
     ## only one point: make a diamond by spreading points vertically
164 169
     ## and horizontally
... ...
@@ -185,11 +190,11 @@ get_glob_encircle <- function(data, panel_scales, coord){
185 190
       mkcoords(x,y)
186 191
     })
187 192
   }
188
-  
193
+
189 194
   disp <- normFun(coords,m)
190
-  
195
+
191 196
   ## browser()
192
-  
197
+
193 198
   gp <- grid::get.gpar()
194 199
   pars1 <- c("colour","linetype","alpha","fill","size")
195 200
   pars2 <- c("col","lty","alpha","fill","lwd")
... ...
@@ -202,7 +207,7 @@ get_glob_encircle <- function(data, panel_scales, coord){
202 207
     shape = coords$s_shape-1,  ## kluge!
203 208
     open = first_row$s_open,
204 209
     gp = gp)
205
-  
210
+
206 211
 }
207 212
 
208 213
 
... ...
@@ -210,15 +215,18 @@ get_glob_encircle <- function(data, panel_scales, coord){
210 215
 #' layer of hilight clade with xspline
211 216
 #'
212 217
 #' @title geom_hilight_encircle
218
+#' @param data data frame to calculate xspline (default = NULL)
213 219
 #' @param node selected node to hilight (required)
220
+#' @param mapping aesthetic mapping (default = NULL)
214 221
 #' @param fill colour fill (default = steelblue)
215 222
 #' @param alpha alpha (transparency) (default = 0.5)
216 223
 #' @param expand expands the xspline clade region only (default = 0)
217
-#' @param spread spread of shape? (default = 0.1)
218
-#' @param linetype Line type of xspline (default = 1)
219
-#' @param size Size of xspline line (default = 1)
220
-#' @param s_shape Corresponds to shape of xspline (default = 0.5)  
221
-#' @param s_open Boolean switch determines if xspline shape is open or closed. (default = FALSE)
224
+#' @param ... addtional parameters, including:
225
+#' 'spread' spread of shape? (default = 0.1),
226
+#' 'linetype' Line type of xspline (default = 1),
227
+#' 'size' Size of xspline line (default = 1),
228
+#' 's_shape' Corresponds to shape of xspline (default = 0.5),
229
+#' 's_open' Boolean switch determines if xspline shape is open or closed. (default = FALSE)
222 230
 #' @return ggplot2
223 231
 #' @export
224 232
 #' @importFrom ggplot2 aes_
... ...
@@ -229,41 +237,41 @@ geom_hilight_encircle <- function(data = NULL,
229 237
                                   alpha       = 0.5,
230 238
                                   expand      = 0, # expand whole hilight region.
231 239
                                   ...) {
232
-  
240
+
233 241
   position    = "identity"
234 242
   na.rm       = TRUE
235 243
   show.legend = NA
236 244
   inherit.aes = FALSE
237 245
   check.aes   = FALSE
238
-  
239
-  
246
+
247
+
240 248
   # Select fields(columns) from the ggtree "data" data.frame to be passed to the GeomHilight ggproto object.
241 249
   default_aes <- aes_( x=~x, y=~y, node=~node, parent=~parent, branch.length=~branch.length )
242
-  
250
+
243 251
   if (is.null(mapping)) {
244 252
     mapping <- default_aes
245 253
   } else {
246 254
     mapping <- modifyList(mapping, default_aes)
247 255
   }
248
-  
256
+
249 257
   # create xspline geom for non-uniform trees, e.g. unrooted layout
250
-  l <- layer( 
258
+  l <- layer(
251 259
     geom = GeomHilight,
252 260
     stat = "identity",
253
-    mapping = mapping,  
254
-    data = data, 
255
-    position = position, 
256
-    show.legend = show.legend, 
261
+    mapping = mapping,
262
+    data = data,
263
+    position = position,
264
+    show.legend = show.legend,
257 265
     inherit.aes = inherit.aes,
258 266
     check.aes = check.aes,
259
-    params = list(clade_root_node = node, 
267
+    params = list(clade_root_node = node,
260 268
                   fill = fill,
261 269
                   alpha = alpha,
262 270
                   expand = expand,
263 271
                   na.rm = na.rm,
264 272
                   ...) # Parameters  to geom
265 273
   )
266
-  
274
+
267 275
   return(l)
268
-  
269
-}
270 276
\ No newline at end of file
277
+
278
+}
... ...
@@ -163,7 +163,7 @@ reroot_node_mapping <- function(tree, tree2) {
163 163
 
164 164
 ##' @importFrom ape reorder.phylo
165 165
 layout.unrooted <- function(tree, branch.length="branch.length", layout.method="equal_angle", ...) {
166
-  
166
+
167 167
     df <- switch(layout.method,
168 168
                  equal_angle = layoutEqualAngle(tree, branch.length),
169 169
                  daylight = layoutDaylight(tree, branch.length)
... ...
@@ -318,7 +318,7 @@ layoutDaylight <- function( tree, branch.length ){
318 318
             result <- applyLayoutDaylight(tree_df, currentNode_id)
319 319
             tree_df <- result$tree
320 320
             total_max <- total_max + result$max_change
321
-            
321
+
322 322
         }
323 323
         # Calculate the running average of angle changes.
324 324
         ave_change <- total_max / length(nodes) * length(i)
... ...
@@ -462,15 +462,15 @@ getTreeArcAngles <- function(df, origin_id, subtree) {
462 462
     # Special case.
463 463
     # get angle from parent of subtree to children
464 464
     children_ids <- getChild.df(df, subtree_root_id)
465
-    
465
+
466 466
     if(length(children_ids) == 2){
467 467
       # get angles from parent to it's two children.
468 468
       theta1 <- getNodeAngle.df(df, origin_id, children_ids[1])
469 469
       theta2 <- getNodeAngle.df(df, origin_id, children_ids[2])
470
-      
470
+
471 471
       delta <- theta1 - theta2
472
-      
473
-  
472
+
473
+
474 474
       # correct delta for points crossing 180/-180 quadrant.
475 475
       if(delta > 1){
476 476
         delta_adj = delta - 2
... ...
@@ -479,7 +479,7 @@ getTreeArcAngles <- function(df, origin_id, subtree) {
479 479
       }else{
480 480
         delta_adj <- delta
481 481
       }
482
-  
482
+
483 483
       if(delta_adj >= 0){
484 484
         theta_left = theta1
485 485
         theta_right = theta2
... ...
@@ -492,7 +492,7 @@ getTreeArcAngles <- function(df, origin_id, subtree) {
492 492
       theta_left <- getNodeAngle.df(df, origin_id, children_ids[1])
493 493
       theta_right <- theta_left
494 494
     }
495
-    
495
+
496 496
   }else{
497 497
     # get the real root of df tree to initialise left and right angles.
498 498
     tree_root <- getRoot.df(df)
... ...
@@ -505,12 +505,12 @@ getTreeArcAngles <- function(df, origin_id, subtree) {
505 505
     }
506 506
 
507 507
   }
508
-  
508
+
509 509
   # no parent angle found.
510 510
   if (is.na(theta_left) ){
511 511
     return(0)
512 512
   }
513
-  
513
+
514 514
 
515 515
   # create vector with named columns
516 516
   # left-hand and right-hand angles between origin node and the extremities of the tree nodes.
... ...
@@ -534,7 +534,7 @@ getTreeArcAngles <- function(df, origin_id, subtree) {
534 534
     # Get angle from origin node to parent node.
535 535
     # Skip if parent_id is a tip or parent and child node are the same.
536 536
     if(origin_id == parent_id | isTip.df(df, parent_id) ){
537
-      next 
537
+      next
538 538
     }
539 539
 
540 540
     theta_parent <- getNodeAngle.df(df, origin_id, parent_id)
... ...
@@ -642,7 +642,7 @@ rotateTreePoints.df <- function(df, pivot_node, nodes, angle){
642 642
     df[node, 'y'] <- sinpitheta * delta_x + cospitheta * delta_y + df[pivot_node, 'y']
643 643
 
644 644
   }
645
-  
645
+
646 646
   # Now update tip labels of rotated tree.
647 647
   # angle is in range [0, 360]
648 648
   for(node in nodes){
... ...
@@ -657,17 +657,17 @@ rotateTreePoints.df <- function(df, pivot_node, nodes, angle){
657 657
           # Update tip label angle, that is parallel to edge.
658 658
           #df[node, 'angle'] <- -90 - 180 * theta_parent_child * sign(theta_parent_child - 1)
659 659
           if(theta_parent_child > 0 ){
660
-            df[node, 'angle'] <- 180 * theta_parent_child   
660
+            df[node, 'angle'] <- 180 * theta_parent_child
661 661
           }else if(theta_parent_child < 0 ){
662 662
             df[node, 'angle'] <- 180 * ( theta_parent_child + 2 )
663 663
           }
664
-          
664
+
665 665
         }
666 666
       }
667 667
     }
668 668
   }
669
-  
670
-  
669
+
670
+
671 671
   return(df)
672 672
 }
673 673
 
... ...
@@ -691,7 +691,7 @@ getNodeAngle.df <- function(df, origin_node_id, node_id){
691 691
 
692 692
 euc.dist <- function(x1, x2) sqrt(sum((x1 - x2) ^ 2))
693 693
 
694
-##' Get the distances from the node to all other nodes in data.frame (including itself if in df)
694
+## Get the distances from the node to all other nodes in data.frame (including itself if in df)
695 695
 getNodeEuclDistances <- function(df, node){
696 696
   # https://stackoverflow.com/questions/24746892/how-to-calculate-euclidian-distance-between-two-points-defined-by-matrix-contain#24747155
697 697
   dist <- NULL
... ...
@@ -831,7 +831,7 @@ getSubtreeUnrooted.df <- function(df, node){
831 831
 
832 832
 
833 833
 getRoot.df <- function(df, node){
834
-  
834
+
835 835
   root <- which(is.na(df$parent))
836 836
   # Check if root was found.
837 837
   if(length(root) == 0){
... ...
@@ -1009,7 +1009,7 @@ isTip <- function(tr, node) {
1009 1009
     return(TRUE)
1010 1010
   }
1011 1011
   return(FALSE)
1012
-  
1012
+
1013 1013
 }
1014 1014
 
1015 1015
 isTip.df <- function(df, node) {
... ...
@@ -4,9 +4,9 @@ ggtree: an R package for visualization and annotation of phylogenetic trees with
4 4
 
5 5
 <img src="https://raw.githubusercontent.com/Bioconductor/BiocStickers/master/ggtree/ggtree.png" height="200" align="right" />
6 6
 
7
-[![releaseVersion](https://img.shields.io/badge/release%20version-1.8.2-green.svg?style=flat)](https://bioconductor.org/packages/ggtree) [![develVersion](https://img.shields.io/badge/devel%20version-1.9.4-green.svg?style=flat)](https://github.com/guangchuangyu/ggtree) [![Bioc](http://www.bioconductor.org/shields/years-in-bioc/ggtree.svg)](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#since) [![total](https://img.shields.io/badge/downloads-18565/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-834/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
7
+[![releaseVersion](https://img.shields.io/badge/release%20version-1.8.2-green.svg?style=flat)](https://bioconductor.org/packages/ggtree) [![develVersion](https://img.shields.io/badge/devel%20version-1.9.4-green.svg?style=flat)](https://github.com/guangchuangyu/ggtree) [![Bioc](http://www.bioconductor.org/shields/years-in-bioc/ggtree.svg)](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#since) [![total](https://img.shields.io/badge/downloads-18823/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-941/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
8 8
 
9
-[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![codecov](https://codecov.io/gh/GuangchuangYu/ggtree/branch/master/graph/badge.svg)](https://codecov.io/gh/GuangchuangYu/ggtree) [![Last-changedate](https://img.shields.io/badge/last%20change-2017--09--04-green.svg)](https://github.com/GuangchuangYu/ggtree/commits/master) [![GitHub forks](https://img.shields.io/github/forks/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/network) [![GitHub stars](https://img.shields.io/github/stars/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/stargazers) [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://awesome-r.com/#awesome-r-graphic-displays)
9
+[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![codecov](https://codecov.io/gh/GuangchuangYu/ggtree/branch/master/graph/badge.svg)](https://codecov.io/gh/GuangchuangYu/ggtree) [![Last-changedate](https://img.shields.io/badge/last%20change-2017--09--12-green.svg)](https://github.com/GuangchuangYu/ggtree/commits/master) [![GitHub forks](https://img.shields.io/github/forks/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/network) [![GitHub stars](https://img.shields.io/github/stars/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/stargazers) [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://awesome-r.com/#awesome-r-graphic-displays)
10 10
 
11 11
 [![platform](http://www.bioconductor.org/shields/availability/devel/ggtree.svg)](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#archives) [![Build Status](http://www.bioconductor.org/shields/build/devel/bioc/ggtree.svg)](https://bioconductor.org/checkResults/devel/bioc-LATEST/ggtree/) [![Linux/Mac Travis Build Status](https://img.shields.io/travis/GuangchuangYu/ggtree/master.svg?label=Mac%20OSX%20%26%20Linux)](https://travis-ci.org/GuangchuangYu/ggtree) [![AppVeyor Build Status](https://img.shields.io/appveyor/ci/Guangchuangyu/ggtree/master.svg?label=Windows)](https://ci.appveyor.com/project/GuangchuangYu/ggtree) [![Backers on Open Collective](https://opencollective.com/ggtree/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/ggtree/sponsors/badge.svg)](#sponsors)
12 12
 
... ...
@@ -27,7 +27,7 @@ Please cite the following article when using `ggtree`:
27 27
 
28 28
 **G Yu**, DK Smith, H Zhu, Y Guan, TTY Lam<sup>\*</sup>. 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.
29 29
 
30
-[![doi](https://img.shields.io/badge/doi-10.1111/2041--210X.12628-green.svg?style=flat)](http://dx.doi.org/10.1111/2041-210X.12628) [![Altmetric](https://img.shields.io/badge/Altmetric-345-green.svg?style=flat)](https://www.altmetric.com/details/10533079) [![citation](https://img.shields.io/badge/cited%20by-36-green.svg?style=flat)](https://scholar.google.com.hk/scholar?oi=bibs&hl=en&cites=7268358477862164627)
30
+[![doi](https://img.shields.io/badge/doi-10.1111/2041--210X.12628-green.svg?style=flat)](http://dx.doi.org/10.1111/2041-210X.12628) [![Altmetric](https://img.shields.io/badge/Altmetric-345-green.svg?style=flat)](https://www.altmetric.com/details/10533079) [![citation](https://img.shields.io/badge/cited%20by-39-green.svg?style=flat)](https://scholar.google.com.hk/scholar?oi=bibs&hl=en&cites=7268358477862164627)
31 31
 
32 32
 ------------------------------------------------------------------------
33 33
 
... ...
@@ -37,7 +37,7 @@ Please cite the following article when using `ggtree`:
37 37
 
38 38
 ### Download stats
39 39
 
40
-[![download](http://www.bioconductor.org/shields/downloads/ggtree.svg)](https://bioconductor.org/packages/stats/bioc/ggtree) [![total](https://img.shields.io/badge/downloads-18565/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-834/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
40
+[![download](http://www.bioconductor.org/shields/downloads/ggtree.svg)](https://bioconductor.org/packages/stats/bioc/ggtree) [![total](https://img.shields.io/badge/downloads-18823/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-941/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
41 41
 
42 42
 <img src="docs/images/dlstats.png" width="890"/>
43 43
 
44 44
Binary files a/docs/images/citation.png and b/docs/images/citation.png differ
45 45
Binary files a/docs/images/dlstats.png and b/docs/images/dlstats.png differ
... ...
@@ -36,10 +36,6 @@ geom_cladelabel2(node, label, offset = 0, offset.text = 0, offset.bar = 0,
36 36
 \item{parse}{logical, whether parse label}
37 37
 
38 38
 \item{...}{additional parameter}
39
-
40
-\item{angle}{angle of text}
41
-
42
-\item{fill}{fill label background, only work with geom='label'}
43 39
 }
44 40
 \value{
45 41
 ggplot layers
... ...
@@ -8,23 +8,24 @@ geom_hilight_encircle(data = NULL, node, mapping = NULL,
8 8
   fill = "steelblue", alpha = 0.5, expand = 0, ...)
9 9
 }
10 10
 \arguments{
11
+\item{data}{data frame to calculate xspline (default = NULL)}
12
+
11 13
 \item{node}{selected node to hilight (required)}
12 14
 
15
+\item{mapping}{aesthetic mapping (default = NULL)}
16
+
13 17
 \item{fill}{colour fill (default = steelblue)}
14 18
 
15 19
 \item{alpha}{alpha (transparency) (default = 0.5)}
16 20
 
17 21
 \item{expand}{expands the xspline clade region only (default = 0)}
18 22
 
19
-\item{spread}{spread of shape? (default = 0.1)}
20
-
21
-\item{linetype}{Line type of xspline (default = 1)}
22
-
23
-\item{size}{Size of xspline line (default = 1)}
24
-
25
-\item{s_shape}{Corresponds to shape of xspline (default = 0.5)}
26
-
27
-\item{s_open}{Boolean switch determines if xspline shape is open or closed. (default = FALSE)}
23
+\item{...}{addtional parameters, including:
24
+'spread' spread of shape? (default = 0.1),
25
+'linetype' Line type of xspline (default = 1),
26
+'size' Size of xspline line (default = 1),
27
+'s_shape' Corresponds to shape of xspline (default = 0.5),
28
+'s_open' Boolean switch determines if xspline shape is open or closed. (default = FALSE)}
28 29
 }
29 30
 \value{
30 31
 ggplot2
31 32
deleted file mode 100644
... ...
@@ -1,11 +0,0 @@
1
-% Generated by roxygen2: do not edit by hand
2
-% Please edit documentation in R/tidytree.R
3
-\name{getNodeEuclDistances}
4
-\alias{getNodeEuclDistances}
5
-\title{Get the distances from the node to all other nodes in data.frame (including itself if in df)}
6
-\usage{
7
-getNodeEuclDistances(df, node)
8
-}
9
-\description{
10
-Get the distances from the node to all other nodes in data.frame (including itself if in df)
11
-}
12 0
deleted file mode 100644
... ...
@@ -1,16 +0,0 @@
1
-% Generated by roxygen2: do not edit by hand
2
-% Please edit documentation in R/stat_chull.R
3
-\name{stat_chull}
4
-\alias{stat_chull}
5
-\title{stat_chull}
6
-\usage{
7
-stat_chull(mapping = NULL, data = NULL, geom = "polygon",
8
-  position = "identity", na.rm = FALSE, show.legend = NA,
9
-  inherit.aes = TRUE, ...)
10
-}
11
-\value{
12
-ggplot2
13
-}
14
-\description{
15
-layer of hilight clade with rectangle
16
-}