Browse code

geom_rootedge

guangchuang yu authored on 13/06/2018 05:54:28
Showing 5 changed files

... ...
@@ -2,7 +2,7 @@ Package: ggtree
2 2
 Type: Package
3 3
 Title: an R package for visualization and annotation of phylogenetic trees with
4 4
     their covariates and other associated data
5
-Version: 1.13.0.005
5
+Version: 1.13.0.006
6 6
 Authors@R: c(
7 7
 	   person("Guangchuang", "Yu",     email = "guangchuangyu@gmail.com", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0002-6485-8781")),
8 8
 	   person("Tommy Tsan-Yuk", "Lam", email = "tylam.tommy@gmail.com",   role = c("aut", "ths")),
... ...
@@ -29,7 +29,7 @@ Imports:
29 29
     scales,
30 30
     tibble,
31 31
     tidyr,
32
-    tidytree (>= 0.1.5),
32
+    tidytree (>= 0.1.9),
33 33
     treeio (>= 1.3.14),
34 34
     utils
35 35
 Suggests:
... ...
@@ -45,6 +45,7 @@ export(geom_nodepoint)
45 45
 export(geom_point)
46 46
 export(geom_point2)
47 47
 export(geom_range)
48
+export(geom_rootedge)
48 49
 export(geom_rootpoint)
49 50
 export(geom_segment2)
50 51
 export(geom_strip)
... ...
@@ -1,5 +1,7 @@
1
-# ggtree 1.13.0.005
1
+# ggtree 1.13.0.006
2 2
 
3
++ `geom_rootedge` (2018-06-13, Wed)
4
+  - <https://github.com/GuangchuangYu/ggtree/issues/183>
3 5
 + `clade_name` parameter added in `collapse` (2018-05-28, Mon)
4 6
   - <https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/bioc-ggtree/0H1PCJPlI1Q/DeZf9EVhBQAJ>
5 7
 + bug fixed of `gheatmap` for rowname subsetting is partial match in R
6 8
new file mode 100644
... ...
@@ -0,0 +1,44 @@
1
+##' display root edge
2
+##'
3
+##'
4
+##' @title geom_rootedge
5
+##' @param rootedge length of rootedge; use phylo$root.edge if rootedge = NULL (by default).
6
+##' @return ggplot layer
7
+##' @export
8
+##' @author Guangchuang Yu
9
+geom_rootedge <- function(rootedge = NULL) {
10
+    mapping <- aes_(x = ~x, y = ~y, xend = ~x, yend = ~y,
11
+                    branch.length = ~branch.length,
12
+                    node = ~node, parent = ~parent)
13
+    layer(
14
+        stat = StatRootEdge,
15
+        data  = NULL,
16
+        mapping = mapping,
17
+        geom = "segment",
18
+        position = "identity",
19
+        show.legend = NA,
20
+        params = list(rootedge = rootedge),
21
+        check.aes = FALSE
22
+    )
23
+
24
+}
25
+
26
+
27
+
28
+StatRootEdge <- ggproto("StatRootEdge", Stat,
29
+                        compute_group = function(self, data, scales, params, rootedge) {
30
+                            d <- data[data$parent == data$node,]
31
+                            if (is.null(rootedge)) {
32
+                                rootedge <- d$branch.length
33
+                            }
34
+                            if (is.null(rootedge) || is.na(rootedge)) {
35
+                                xend <- d$x
36
+                            } else {
37
+                                xend <- -rootedge
38
+                            }
39
+
40
+                            data.frame(x = d$x, y = d$y,
41
+                                       xend = xend, yend = d$y)
42
+                        },
43
+                        required_aes = c("x", "y", "xend", "yend")
44
+                        )
0 45
new file mode 100644
... ...
@@ -0,0 +1,20 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/geom_rootedge.R
3
+\name{geom_rootedge}
4
+\alias{geom_rootedge}
5
+\title{geom_rootedge}
6
+\usage{
7
+geom_rootedge(rootedge = NULL)
8
+}
9
+\arguments{
10
+\item{rootedge}{length of rootedge; use phylo$root.edge if rootedge = NULL (by default).}
11
+}
12
+\value{
13
+ggplot layer
14
+}
15
+\description{
16
+display root edge
17
+}
18
+\author{
19
+Guangchuang Yu
20
+}