... | ... |
@@ -117,6 +117,7 @@ export(rtree) |
117 | 117 |
export(scaleClade) |
118 | 118 |
export(scale_color) |
119 | 119 |
export(scale_x_ggtree) |
120 |
+export(set_tree_xlim) |
|
120 | 121 |
export(stat_balance) |
121 | 122 |
export(stat_hilight) |
122 | 123 |
export(subview) |
... | ... |
@@ -189,6 +190,7 @@ importFrom(ggplot2,element_rect) |
189 | 190 |
importFrom(ggplot2,facet_grid) |
190 | 191 |
importFrom(ggplot2,fortify) |
191 | 192 |
importFrom(ggplot2,geom_bar) |
193 |
+importFrom(ggplot2,geom_blank) |
|
192 | 194 |
importFrom(ggplot2,geom_rect) |
193 | 195 |
importFrom(ggplot2,geom_segment) |
194 | 196 |
importFrom(ggplot2,geom_text) |
... | ... |
@@ -1,5 +1,11 @@ |
1 | 1 |
CHANGES IN VERSION 1.7.1 |
2 | 2 |
------------------------ |
3 |
+ o set_tree_xlim function and test <2016-10-31, Mon> |
|
4 |
+ + set x axis limit for Tree panel for facet_plot |
|
5 |
+ o update read.nhx <2016-10-30, Sun> |
|
6 |
+ + add tip numbers to @nhx_tags and add tests |
|
7 |
+ + https://github.com/GuangchuangYu/ggtree/pull/83 |
|
8 |
+ + store nhx_tags$node as numeric values <2016-10-31, Mon> |
|
3 | 9 |
o facet_plot supports ggbio::geom_alignment <2016-10-26, Wed> |
4 | 10 |
+ https://github.com/tengfei/ggbio/issues/83 |
5 | 11 |
o make tree stats available in facet_plot <2016-10-24, Mon> |
... | ... |
@@ -5,7 +5,7 @@ |
5 | 5 |
##' @param file nhx file |
6 | 6 |
##' @return nhx object |
7 | 7 |
##' @export |
8 |
-##' @author Guangchuang Yu \url{http://ygc.name} |
|
8 |
+##' @author Guangchuang Yu \url{https://guangchuangyu.github.io} |
|
9 | 9 |
read.nhx <- function(file) { |
10 | 10 |
treetext <- suppressWarnings(readLines(file)) |
11 | 11 |
treetext <- treetext[treetext != ""] |
... | ... |
@@ -27,7 +27,7 @@ read.nhx <- function(file) { |
27 | 27 |
|
28 | 28 |
phylo2 <- read.tree(text = tree2) |
29 | 29 |
treeinfo <- fortify(phylo2) |
30 |
- node <- as.character(treeinfo$node[match(nlab, sub(".+(X\\d+)$","\\1",treeinfo$label))]) |
|
30 |
+ node <- treeinfo$node[match(nlab, sub(".+(X\\d+)$","\\1",treeinfo$label))] # as.character |
|
31 | 31 |
|
32 | 32 |
nhx.matches <- gregexpr("(\\w+)?(:?\\d*\\.?\\d*[Ee]?[\\+\\-]?\\d*)?\\[&&NHX.*?\\]", treetext) |
33 | 33 |
matches <- nhx.matches[[1]] |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
##' plot tree associated data in an additional panel |
2 | 2 |
##' |
3 |
-##' |
|
3 |
+##' |
|
4 | 4 |
##' @title facet_plot |
5 | 5 |
##' @param p tree view |
6 | 6 |
##' @param panel panel name for plot of input data |
... | ... |
@@ -27,3 +27,29 @@ add_panel <- function(p, panel) { |
27 | 27 |
p$data <- df |
28 | 28 |
p + facet_grid(.~panel, scales="free_x") |
29 | 29 |
} |
30 |
+ |
|
31 |
+##' set x axis limits for Tree panel |
|
32 |
+##' |
|
33 |
+##' |
|
34 |
+##' @title set_tree_xlim |
|
35 |
+##' @param tree_view tree view |
|
36 |
+##' @param xlim xlim, should be of length 2 |
|
37 |
+##' @return updated tree view |
|
38 |
+##' @export |
|
39 |
+##' @importFrom ggplot2 geom_blank |
|
40 |
+##' @author guangchuang yu |
|
41 |
+set_tree_xlim <- function(tree_view, xlim) { |
|
42 |
+ if (length(xlim) != 2) { |
|
43 |
+ stop('-> xlim should be of length 2...') |
|
44 |
+ } |
|
45 |
+ x <- tree_view$data$x |
|
46 |
+ if (is.na(xlim[1])) { |
|
47 |
+ xlim[1] <- min(x) |
|
48 |
+ } |
|
49 |
+ if (is.na(xlim[2])) { |
|
50 |
+ xlim[2] <- max(x) |
|
51 |
+ } |
|
52 |
+ dummy <- data.frame(x=xlim, panel='Tree') |
|
53 |
+ tree_view + geom_blank(aes(x=x), dummy, inherit.aes = FALSE) |
|
54 |
+} |
|
55 |
+ |
... | ... |
@@ -3,7 +3,7 @@ ggtree: an R package for visualization and annotation of phylogenetic trees with |
3 | 3 |
|
4 | 4 |
[](https://bioconductor.org/packages/ggtree) [](https://github.com/GuangchuangYu/ggtree) [](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#since) [](https://bioconductor.org/packages/stats/bioc/ggtree) [](https://bioconductor.org/packages/stats/bioc/ggtree) |
5 | 5 |
|
6 |
-[](http://www.repostatus.org/#active) [](https://codecov.io/gh/GuangchuangYu/ggtree) [](https://github.com/GuangchuangYu/ggtree/commits/master) [](https://github.com/GuangchuangYu/ggtree/network) [](https://github.com/GuangchuangYu/ggtree/stargazers) [](https://awesome-r.com/#awesome-r-graphic-displays) |
|
6 |
+[](http://www.repostatus.org/#active) [](https://codecov.io/gh/GuangchuangYu/ggtree) [](https://github.com/GuangchuangYu/ggtree/commits/master) [](https://github.com/GuangchuangYu/ggtree/network) [](https://github.com/GuangchuangYu/ggtree/stargazers) [](https://awesome-r.com/#awesome-r-graphic-displays) |
|
7 | 7 |
|
8 | 8 |
[](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#archives) [](https://bioconductor.org/checkResults/devel/bioc-LATEST/ggtree/) [](https://travis-ci.org/GuangchuangYu/ggtree) [](https://ci.appveyor.com/project/GuangchuangYu/ggtree) [](http://bioconda.github.io/recipes/bioconductor-ggtree/README.html) |
9 | 9 |
|
22 | 22 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,23 @@ |
1 |
+% Generated by roxygen2: do not edit by hand |
|
2 |
+% Please edit documentation in R/facet_plot.R |
|
3 |
+\name{set_tree_xlim} |
|
4 |
+\alias{set_tree_xlim} |
|
5 |
+\title{set_tree_xlim} |
|
6 |
+\usage{ |
|
7 |
+set_tree_xlim(tree_view, xlim) |
|
8 |
+} |
|
9 |
+\arguments{ |
|
10 |
+\item{tree_view}{tree view} |
|
11 |
+ |
|
12 |
+\item{xlim}{xlim, should be of length 2} |
|
13 |
+} |
|
14 |
+\value{ |
|
15 |
+updated tree view |
|
16 |
+} |
|
17 |
+\description{ |
|
18 |
+set x axis limits for Tree panel |
|
19 |
+} |
|
20 |
+\author{ |
|
21 |
+guangchuang yu |
|
22 |
+} |
|
23 |
+ |
0 | 24 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,14 @@ |
1 |
+context("set_tree_xlim") |
|
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(set_tree_xlim(p, 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 |
+}) |