Browse code

expand_xlim

guangchuang yu authored on 01/11/2016 02:23:02
Showing 9 changed files

... ...
@@ -3,7 +3,7 @@ Type: Package
3 3
 Title: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data
4 4
 Version: 1.7.2
5 5
 Authors@R: c(
6
-	   person("Guangchuang", "Yu", email = "guangchuangyu@gmail.com", role = c("aut", "cre")),
6
+	   person("Guangchuang", "Yu", email = "guangchuangyu@gmail.com", role = c("aut", "cre", "cph")),
7 7
 	   person("Tommy Tsan-Yuk", "Lam", email = "tylam.tommy@gmail.com", rol = c("aut", "ths")),
8 8
 	   person("Justin", "Silverman", email = "jsilve24@gmail.com", rol = "ctb", comment = "geom_balance"),
9 9
 	   person("Casey", "Dunn", email = "casey_dunn@brown.edu", rol = "ctb",
... ...
@@ -40,6 +40,7 @@ export(collapse)
40 40
 export(decimal2Date)
41 41
 export(download.phylopic)
42 42
 export(expand)
43
+export(expand_xlim)
43 44
 export(facet_plot)
44 45
 export(flip)
45 46
 export(geom_aline)
... ...
@@ -1,12 +1,14 @@
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 5
  o bug fixed of parsing tree text in beast file <2016-10-31, Mon>
4 6
    + https://github.com/GuangchuangYu/ggtree/issues/84
5 7
 
6 8
 CHANGES IN VERSION 1.7.1
7 9
 ------------------------
8 10
  o xlim_tree layer and test <2016-10-31, Mon>
9
-   + set x axis limit for Tree panel for facet_plot
11
+   + set x axis limits for Tree panel for facet_plot
10 12
  o update read.nhx <2016-10-30, Sun>
11 13
    + add tip numbers to @nhx_tags and add tests
12 14
    + https://github.com/GuangchuangYu/ggtree/pull/83
... ...
@@ -20,25 +20,11 @@ facet_plot <- function(p, panel, data, geom, mapping=NULL, ...) {
20 20
 ##' @importFrom ggplot2 facet_grid
21 21
 add_panel <- function(p, panel) {
22 22
     df <- p$data
23
-    if (is.null(df$panel)) {
24
-        df$panel <- factor("Tree")
23
+    if (is.null(df$.panel)) {
24
+        df$.panel <- factor("Tree")
25 25
     }
26
-    levels(df$panel) %<>% c(., panel)
26
+    levels(df$.panel) %<>% c(., panel)
27 27
     p$data <- df
28
-    p + facet_grid(.~panel, scales="free_x")
29
-}
30
-
31
-##' set x axis limits for Tree panel
32
-##'
33
-##'
34
-##' @title xlim_tree
35
-##' @param xlim xlim, should be of length 2
36
-##' @return updated tree view
37
-##' @export
38
-##' @importFrom ggplot2 geom_blank
39
-##' @author guangchuang yu
40
-xlim_tree <- function(xlim) {
41
-    dummy <- data.frame(x=xlim, panel='Tree')
42
-    geom_blank(aes_(x=~x), dummy, inherit.aes = FALSE)
28
+    p + facet_grid(.~.panel, scales="free_x")
43 29
 }
44 30
 
... ...
@@ -100,19 +100,19 @@
100 100
 ##' @author Guangchuang Yu
101 101
 `%+>%` <- function(p, data) {
102 102
     df <- p$data
103
-    lv <- levels(df$panel)
103
+    lv <- levels(df$.panel)
104 104
 
105 105
     if (is(data, "GRanges") || is(data, "GRangesList")) {
106 106
         names(data) <- df$y[match(names(data), df$label)]
107 107
         res <- data[order(as.numeric(names(data)))]
108 108
         mcols <- get_fun_from_pkg("GenomicRanges", "mcols")
109 109
         `mcols<-` <- get_fun_from_pkg("GenomicRanges", "`mcols<-`")
110
-        mcols(res)$panel <- factor(lv[length(lv)], levels=lv)
110
+        mcols(res)$.panel <- factor(lv[length(lv)], levels=lv)
111 111
     } else if (is(data, "data.frame") || is(data, "tbl_df")) {
112 112
         data <- as.data.frame(data)
113 113
         ## res <- merge(df[, c('label', 'y')], data, by.x='label', by.y=1) ## , all.x=TRUE)
114 114
         res <- merge(df[, !names(df) %in% c('node', 'parent', 'x', 'branch', 'angle')], data, by.x='label', by.y=1)
115
-        res$panel <- factor(lv[length(lv)], levels=lv)
115
+        res$.panel <- factor(lv[length(lv)], levels=lv)
116 116
     } else {
117 117
         stop("input 'data' is not supported...")
118 118
     }
119 119
new file mode 100644
... ...
@@ -0,0 +1,28 @@
1
+##' set x axis limits for Tree panel
2
+##'
3
+##'
4
+##' @title xlim_tree
5
+##' @param xlim xlim
6
+##' @return updated tree view
7
+##' @export
8
+##' @author guangchuang yu
9
+xlim_tree <- function(xlim) {
10
+    expand_xlim(xlim, panel='Tree')
11
+}
12
+
13
+
14
+##' expand x axis limits for specific panel
15
+##'
16
+##'
17
+##' @title expand_xlim
18
+##' @param xlim xlim
19
+##' @param panel panel
20
+##' @return updated tree view
21
+##' @importFrom ggplot2 geom_blank
22
+##' @export
23
+##' @author guangchuang yu
24
+expand_xlim <- function(xlim, panel) {
25
+    dummy <- data.frame(x=xlim, .panel=panel)
26
+    geom_blank(aes_(x=~x), dummy, inherit.aes = FALSE)
27
+}
28
+
... ...
@@ -1,9 +1,9 @@
1 1
 ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data
2 2
 ===========================================================================================================================
3 3
 
4
-[![releaseVersion](https://img.shields.io/badge/release%20version-1.6.1-green.svg?style=flat)](https://bioconductor.org/packages/ggtree) [![develVersion](https://img.shields.io/badge/devel%20version-1.7.1-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-15734/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-1678/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
4
+[![releaseVersion](https://img.shields.io/badge/release%20version-1.6.1-green.svg?style=flat)](https://bioconductor.org/packages/ggtree) [![develVersion](https://img.shields.io/badge/devel%20version-1.7.2-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-15734/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-1678/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
5 5
 
6
-[![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-2016--10--31-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)
6
+[![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-2016--11--01-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)
7 7
 
8 8
 [![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) [![install with bioconda](https://img.shields.io/badge/install%20with-bioconda-green.svg?style=flat)](http://bioconda.github.io/recipes/bioconductor-ggtree/README.html)
9 9
 
10 10
new file mode 100644
... ...
@@ -0,0 +1,23 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/xlim.R
3
+\name{expand_xlim}
4
+\alias{expand_xlim}
5
+\title{expand_xlim}
6
+\usage{
7
+expand_xlim(xlim, panel)
8
+}
9
+\arguments{
10
+\item{xlim}{xlim}
11
+
12
+\item{panel}{panel}
13
+}
14
+\value{
15
+updated tree view
16
+}
17
+\description{
18
+expand x axis limits for specific panel
19
+}
20
+\author{
21
+guangchuang yu
22
+}
23
+
... ...
@@ -1,5 +1,5 @@
1 1
 % Generated by roxygen2: do not edit by hand
2
-% Please edit documentation in R/facet_plot.R
2
+% Please edit documentation in R/xlim.R
3 3
 \name{xlim_tree}
4 4
 \alias{xlim_tree}
5 5
 \title{xlim_tree}
... ...
@@ -7,7 +7,7 @@
7 7
 xlim_tree(xlim)
8 8
 }
9 9
 \arguments{
10
-\item{xlim}{xlim, should be of length 2}
10
+\item{xlim}{xlim}
11 11
 }
12 12
 \value{
13 13
 updated tree view