Commit information:
Commit id: 8572e12d6dace6f8953556a4a695b0543291eb35
%<%
Committed by: GuangchuangYu
Author Name: GuangchuangYu
Commit date: 2015-02-09 21:36:40 +0800
Author date: 2015-02-09 21:36:40 +0800
git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/ggtree@99235 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
Package: ggtree |
2 | 2 |
Type: Package |
3 | 3 |
Title: a phylogenetic tree viewer for different types of tree annotations |
4 |
-Version: 0.99.14 |
|
4 |
+Version: 0.99.15 |
|
5 | 5 |
Author: Guangchuang Yu |
6 | 6 |
Maintainer: Guangchuang Yu <guangchuangyu@gmail.com> |
7 | 7 |
Description: ggtree extends the ggplot2 plotting system which implemented the |
... | ... |
@@ -5,6 +5,11 @@ |
5 | 5 |
##' @param tr phylo object |
6 | 6 |
##' @param showDistance add distance legend, logical |
7 | 7 |
##' @param layout one of phylogram, dendrogram, cladogram, fan, radial and unrooted |
8 |
+##' @param yscale y scale |
|
9 |
+##' @param ladderize logical |
|
10 |
+##' @param right logical |
|
11 |
+##' @param branch.length variable for scaling branch |
|
12 |
+##' @param ndigits number of digits to round numerical annotation variable |
|
8 | 13 |
##' @param ... additional parameter |
9 | 14 |
##' @return tree |
10 | 15 |
##' @importFrom ggplot2 ggplot |
... | ... |
@@ -20,7 +25,13 @@ |
20 | 25 |
##' require(ape) |
21 | 26 |
##' tr <- rtree(10) |
22 | 27 |
##' ggtree(tr) |
23 |
-ggtree <- function(tr, showDistance=FALSE, layout="phylogram", ...) { |
|
28 |
+ggtree <- function(tr, |
|
29 |
+ showDistance=FALSE, |
|
30 |
+ layout="phylogram", |
|
31 |
+ yscale="none", |
|
32 |
+ ladderize = TRUE, right=FALSE, |
|
33 |
+ branch.length="branch.length", |
|
34 |
+ ndigits = NULL, ...) { |
|
24 | 35 |
d <- x <- y <- NULL |
25 | 36 |
if (layout == "fan") { |
26 | 37 |
## layout <- "phylogram" |
... | ... |
@@ -34,7 +45,13 @@ ggtree <- function(tr, showDistance=FALSE, layout="phylogram", ...) { |
34 | 45 |
} else { |
35 | 46 |
type <- "none" |
36 | 47 |
} |
37 |
- p <- ggplot(tr, aes(x, y), layout=layout, ...) |
|
48 |
+ p <- ggplot(tr, aes(x, y), |
|
49 |
+ layout = layout, |
|
50 |
+ yscale = yscale, |
|
51 |
+ ladderize = ladderize, |
|
52 |
+ right = right, |
|
53 |
+ branch.length = branch.length, |
|
54 |
+ ndigits = ndigits, ...) |
|
38 | 55 |
|
39 | 56 |
p <- p + geom_tree(layout, ...) + xlab("") + ylab("") + theme_tree2() |
40 | 57 |
|
... | ... |
@@ -47,7 +64,12 @@ ggtree <- function(tr, showDistance=FALSE, layout="phylogram", ...) { |
47 | 64 |
if (showDistance == FALSE) { |
48 | 65 |
p <- p + theme_tree() |
49 | 66 |
} |
50 |
- attr(p, "layout") <- layout |
|
67 |
+ attr(p, "param") <- list(layout = layout, |
|
68 |
+ yscale = yscale, |
|
69 |
+ ladderize = ladderize, |
|
70 |
+ right = right, |
|
71 |
+ branch.length = branch.length, |
|
72 |
+ ndigits = ndigits) |
|
51 | 73 |
return(p) |
52 | 74 |
} |
53 | 75 |
|
... | ... |
@@ -204,6 +204,10 @@ fortify.codeml <- function(model, data, |
204 | 204 |
...) { |
205 | 205 |
|
206 | 206 |
dNdS <- model@mlc@dNdS |
207 |
+ if (branch.length == "branch.length") { |
|
208 |
+ message("branch.length setting to mlc.branch.length by default...") |
|
209 |
+ branch.length <- "mlc.branch.length" |
|
210 |
+ } |
|
207 | 211 |
length <- match.arg(branch.length, |
208 | 212 |
c("none", |
209 | 213 |
"mlc.branch.length", |
... | ... |
@@ -267,8 +267,14 @@ is.tree_attribute_ <- function(p, var) { |
267 | 267 |
} |
268 | 268 |
|
269 | 269 |
`%place%` <- function(pg, tree) { |
270 |
- layout <- attr(pg, "layout") |
|
271 |
- pg$data <- fortify(tree, layout=layout) |
|
270 |
+ param <- attr(pg, "param") |
|
271 |
+ pg$data <- fortify(tree, |
|
272 |
+ layout = param[["layout"]], |
|
273 |
+ yscale = param[["yscale"]], |
|
274 |
+ ladderize = param[["ladderize"]], |
|
275 |
+ right = param[["right"]], |
|
276 |
+ branch.length = param[["branch.length"]], |
|
277 |
+ ndigits = param[["ndigits"]]) |
|
272 | 278 |
return(pg) |
273 | 279 |
} |
274 | 280 |
|
... | ... |
@@ -8,7 +8,9 @@ |
8 | 8 |
\title{visualizing phylogenetic tree and heterogenous associated data based on grammar of graphics |
9 | 9 |
\code{ggtree} provides functions for visualizing phylogenetic tree and its associated data in R.} |
10 | 10 |
\usage{ |
11 |
-ggtree(tr, showDistance = FALSE, layout = "phylogram", ...) |
|
11 |
+ggtree(tr, showDistance = FALSE, layout = "phylogram", yscale = "none", |
|
12 |
+ ladderize = TRUE, right = FALSE, branch.length = "branch.length", |
|
13 |
+ ndigits = NULL, ...) |
|
12 | 14 |
} |
13 | 15 |
\arguments{ |
14 | 16 |
\item{tr}{phylo object} |
... | ... |
@@ -17,6 +19,16 @@ ggtree(tr, showDistance = FALSE, layout = "phylogram", ...) |
17 | 19 |
|
18 | 20 |
\item{layout}{one of phylogram, dendrogram, cladogram, fan, radial and unrooted} |
19 | 21 |
|
22 |
+\item{yscale}{y scale} |
|
23 |
+ |
|
24 |
+\item{ladderize}{logical} |
|
25 |
+ |
|
26 |
+\item{right}{logical} |
|
27 |
+ |
|
28 |
+\item{branch.length}{variable for scaling branch} |
|
29 |
+ |
|
30 |
+\item{ndigits}{number of digits to round numerical annotation variable} |
|
31 |
+ |
|
20 | 32 |
\item{...}{additional parameter} |
21 | 33 |
} |
22 | 34 |
\value{ |
... | ... |
@@ -101,11 +101,11 @@ grid.arrange(ggtree(tree) + ggtitle("phylogram layout"), |
101 | 101 |
ggtree(tree, layout="dendrogram") + ggtitle("dendrogram layout"), |
102 | 102 |
ggtree(tree, layout="cladogram") + ggtitle("cladogram layout"), |
103 | 103 |
ggtree(tree, layout="cladogram", branch.length="none") + |
104 |
- scale_x_reverse()+coord_flip() + ggtitle("cladogram layout"), |
|
104 |
+ scale_x_reverse()+coord_flip() + ggtitle("cladogram layout"), |
|
105 | 105 |
ggtree(tree, layout="fan") + ggtitle("fan layout"), |
106 | 106 |
ggtree(tree, layout="unrooted") + ggtitle("unrooted layout"), |
107 | 107 |
ncol=2) |
108 |
-``` |
|
108 |
+``` |
|
109 | 109 |
|
110 | 110 |
### two dimensional tree |
111 | 111 |
|
... | ... |
@@ -146,16 +146,16 @@ ggtree(tree) + theme_tree2() |
146 | 146 |
Another way is to show the edge length of the tree. Besides, the scale of branch length can be specify via _`scale_x_continuous()`_. |
147 | 147 |
```{r fig.width=3, fig.height=3, warning=FALSE, fig.align="center"} |
148 | 148 |
ggtree(tree, showDistance=TRUE) + |
149 |
- geom_text(aes(label=branch.length, x=branch), size = 3, |
|
150 |
- vjust=-0.5, color="#F06C45") + |
|
149 |
+ geom_text(aes(label=branch.length, x=branch), size = 3, |
|
150 |
+ vjust=-0.5, color="#F06C45") + |
|
151 | 151 |
scale_x_continuous(breaks=seq(0, 60, 5)) |
152 | 152 |
``` |
153 | 153 |
|
154 | 154 |
User can also use _`geom_segment`_ and _`geom_text`_ to specify the position and length of distance legend: |
155 | 155 |
```{r fig.width=3, fig.height=3, warning=FALSE, fig.align="center"} |
156 | 156 |
ggtree(tree) + |
157 |
- geom_segment(x=0, y=12, xend=10, yend=12) + |
|
158 |
- geom_text(x=5, y=12.5, label=5, size=4) |
|
157 |
+ geom_segment(x=0, y=12, xend=10, yend=12) + |
|
158 |
+ geom_text(x=5, y=12.5, label=5, size=4) |
|
159 | 159 |
``` |
160 | 160 |
|
161 | 161 |
## display nodes/tips |
... | ... |
@@ -409,11 +409,11 @@ We implemented several _`plot`_ methods for easily viewing annotation data. User |
409 | 409 |
In the following example, we use the _`codeml`_ object to visualize the $\omega$ (_`dN/dS`_) tree, and annotate the tree with _`dN`_ and _`dS`_. |
410 | 410 |
```{r fig.width=12, fig.height=10, width=60, warning=FALSE, fig.align="center"} |
411 | 411 |
ggtree(ml, branch.length="dN_vs_dS") + |
412 |
- geom_text(aes(x=branch, label=dN), |
|
413 |
- size=3, vjust=-0.5, color="red") + |
|
414 |
- geom_text(aes(x=branch, label=dS), |
|
415 |
- size=3, vjust=1.2, color="darkgreen") |
|
416 |
-``` |
|
412 |
+ geom_text(aes(x=branch, label=dN), |
|
413 |
+ size=3, vjust=-0.5, color="red") + |
|
414 |
+ geom_text(aes(x=branch, label=dS), |
|
415 |
+ size=3, vjust=1.2, color="darkgreen") |
|
416 |
+``` |
|
417 | 417 |
|
418 | 418 |
|
419 | 419 |
## user specific annotation |
... | ... |
@@ -428,9 +428,9 @@ nwk <- system.file("extdata", "sample.nwk", package="ggtree") |
428 | 428 |
tree <- read.tree(nwk) |
429 | 429 |
p <- ggtree(tree) |
430 | 430 |
|
431 |
-dd <- data.frame(taxa=LETTERS[1:13], |
|
432 |
- place=c(rep("GZ", 5), rep("HK", 3), rep("CZ", 4), NA), |
|
433 |
- value=round(abs(rnorm(13, mean=70, sd=10)), digits=1)) |
|
431 |
+dd <- data.frame(taxa = LETTERS[1:13], |
|
432 |
+ place = c(rep("GZ", 5), rep("HK", 3), rep("CZ", 4), NA), |
|
433 |
+ value = round(abs(rnorm(13, mean=70, sd=10)), digits=1)) |
|
434 | 434 |
## you don't need to order the data |
435 | 435 |
## data was reshuffled just for demonstration |
436 | 436 |
dd <- dd[sample(1:13, 13), ] |