Browse code

xlim_expand

guangchuang yu authored on 01/11/2016 02:38:09
Showing6 changed files

... ...
@@ -40,7 +40,6 @@ export(collapse)
40 40
 export(decimal2Date)
41 41
 export(download.phylopic)
42 42
 export(expand)
43
-export(expand_xlim)
44 43
 export(facet_plot)
45 44
 export(flip)
46 45
 export(geom_aline)
... ...
@@ -127,6 +126,7 @@ export(theme_tree)
127 126
 export(theme_tree2)
128 127
 export(viewClade)
129 128
 export(write.jplace)
129
+export(xlim_expand)
130 130
 export(xlim_tree)
131 131
 exportClasses(apeBootstrap)
132 132
 exportClasses(beast)
... ...
@@ -1,7 +1,7 @@
1 1
 CHANGES IN VERSION 1.7.2
2 2
 ------------------------
3
- o expand_xlim for setting x axis limits of specific panel <2016-11-01, Tue>
4
-   + xlim_tree is now a specific case of expand_xlim(xlim, panel='Tree')
3
+ o xlim_expand for setting x axis limits of specific panel <2016-11-01, Tue>
4
+   + xlim_tree is now a specific case of xlim_expand(xlim, panel='Tree')
5 5
  o bug fixed of parsing tree text in beast file <2016-10-31, Mon>
6 6
    + https://github.com/GuangchuangYu/ggtree/issues/84
7 7
 
... ...
@@ -7,21 +7,21 @@
7 7
 ##' @export
8 8
 ##' @author guangchuang yu
9 9
 xlim_tree <- function(xlim) {
10
-    expand_xlim(xlim, panel='Tree')
10
+    xlim_expand(xlim, panel='Tree')
11 11
 }
12 12
 
13 13
 
14 14
 ##' expand x axis limits for specific panel
15 15
 ##'
16 16
 ##'
17
-##' @title expand_xlim
17
+##' @title xlim_expand
18 18
 ##' @param xlim xlim
19 19
 ##' @param panel panel
20 20
 ##' @return updated tree view
21 21
 ##' @importFrom ggplot2 geom_blank
22 22
 ##' @export
23 23
 ##' @author guangchuang yu
24
-expand_xlim <- function(xlim, panel) {
24
+xlim_expand <- function(xlim, panel) {
25 25
     dummy <- data.frame(x=xlim, .panel=panel)
26 26
     geom_blank(aes_(x=~x), dummy, inherit.aes = FALSE)
27 27
 }
28 28
similarity index 75%
29 29
rename from man/expand_xlim.Rd
30 30
rename to man/xlim_expand.Rd
... ...
@@ -1,10 +1,10 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/xlim.R
3
-\name{expand_xlim}
4
-\alias{expand_xlim}
5
-\title{expand_xlim}
3
+\name{xlim_expand}
4
+\alias{xlim_expand}
5
+\title{xlim_expand}
6 6
 \usage{
7
-expand_xlim(xlim, panel)
7
+xlim_expand(xlim, panel)
8 8
 }
9 9
 \arguments{
10 10
 \item{xlim}{xlim}
11 11
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+context("xlim_expand")
2
+
3
+test_that("dummy layer to set x axis limits of Tree panel", {
4
+    set.seed(2016-10-31)
5
+    tr <- rtree(50)
6
+    tr$tip.label <- paste(tr$tip.label, tr$tip.label, sep="_")
7
+    p <- ggtree(tr) + geom_tiplab(align=TRUE) + theme_tree2()
8
+
9
+    d <- data.frame(id = tr$tip.label, v= rnorm(50))
10
+
11
+    p2 <- facet_plot(p + xlim_tree(c(NA, 6)), geom=geom_point, data=d, mapping=aes(x=v), panel='dot')
12
+
13
+    expect_true(is.ggplot(p2)) # should plot appropriately
14
+})
15
+
16
+
17
+
18
+test_that("dummy layer to set x axis limits of data panel", {
19
+    set.seed(2016-10-31)
20
+    tr <- rtree(50)
21
+    tr$tip.label <- paste(tr$tip.label, tr$tip.label, sep="_")
22
+    p <- ggtree(tr) + geom_tiplab(align=TRUE) + theme_tree2()
23
+
24
+    d <- data.frame(id = tr$tip.label, v= rnorm(50))
25
+
26
+    p2 <- facet_plot(p, geom=geom_point, data=d, mapping=aes(x=v), panel='dot') + xlim_expand(c(-4, 4), 'dot')
27
+
28
+    expect_true(is.ggplot(p2)) # should plot appropriately
29
+})
30
+
0 31
deleted file mode 100644
... ...
@@ -1,14 +0,0 @@
1
-context("xlim_tree")
2
-
3
-test_that("dummy layer to set x axis limits of Tree panel", {
4
-    set.seed(2016-10-31)
5
-    tr <- rtree(50)
6
-    tr$tip.label <- paste(tr$tip.label, tr$tip.label, sep="_")
7
-    p <- ggtree(tr) + geom_tiplab(align=TRUE) + theme_tree2()
8
-
9
-    d <- data.frame(id = tr$tip.label, v= rnorm(50))
10
-
11
-    p2 <- facet_plot(p + xlim_tree(c(NA, 6)), geom=geom_point, data=d, mapping=aes(x=v), panel='dot') + ggtitle('*set_tree_xlim* only change x axis limits of *Tree* panel')
12
-
13
-    expect_true(is.ggplot(p2)) # should plot appropriately
14
-})