... | ... |
@@ -23,7 +23,7 @@ ggdensitree( |
23 | 23 |
|
24 | 24 |
\item{tip.order}{the order of the tips by a character vector of taxa names; or an integer, N, to order the tips by the order of the tips in the Nth tree; 'mode' to order the tips by the most common order; 'mds' to order the tips based on MDS of the path length between the tips; or 'mds_dist' to order the tips based on MDS of the distance between the tips (default: 'mode')} |
25 | 25 |
|
26 |
-\item{align.tips}{TRUE to align trees by their tips and FALSE to align trees by their root (default: TRUE)} |
|
26 |
+\item{align.tips}{TRUE (default) to align trees by their tips and FALSE to align trees by their root} |
|
27 | 27 |
|
28 | 28 |
\item{jitter}{deviation to jitter tips} |
29 | 29 |
|
... | ... |
@@ -35,6 +35,10 @@ tree layer |
35 | 35 |
\description{ |
36 | 36 |
drawing phylogenetic trees from list of phylo objects |
37 | 37 |
} |
38 |
+\details{ |
|
39 |
+The trees plotted by 'ggdensitree()' will be stacked on top of each other and the |
|
40 |
+structures of the trees will be rotated to ensure the consistency of the tip order. |
|
41 |
+} |
|
38 | 42 |
\examples{ |
39 | 43 |
require(ape) |
40 | 44 |
require(dplyr) |
... | ... |
@@ -74,6 +78,11 @@ otu.trees <- lapply(example.trees, groupOTU, grp) |
74 | 78 |
# Plot multiple trees colored by OTU |
75 | 79 |
ggdensitree(otu.trees, aes(colour=group), alpha=1/6, tip.order='mds') + scale_colour_manual(values=c("black", "red", "green", "blue")) |
76 | 80 |
} |
81 |
+\references{ |
|
82 |
+For more detailed demonstration of this function, please refer to chapter 4.4.2 of |
|
83 |
+\emph{Data Integration, Manipulation and Visualization of Phylogenetic Trees} |
|
84 |
+\url{http://yulab-smu.top/treedata-book/index.html} by Guangchuang Yu. |
|
85 |
+} |
|
77 | 86 |
\author{ |
78 | 87 |
Yu Guangchuang, Bradley R. Jones |
79 | 88 |
} |
... | ... |
@@ -8,7 +8,7 @@ ggdensitree( |
8 | 8 |
data = NULL, |
9 | 9 |
mapping = NULL, |
10 | 10 |
layout = "slanted", |
11 |
- tip.order = "mds_dist", |
|
11 |
+ tip.order = "mode", |
|
12 | 12 |
align.tips = TRUE, |
13 | 13 |
jitter = 0, |
14 | 14 |
... |
... | ... |
@@ -21,7 +21,7 @@ ggdensitree( |
21 | 21 |
|
22 | 22 |
\item{layout}{one of 'slanted', 'rectangluar', 'fan', 'circular' or 'radial' (default: 'slanted')} |
23 | 23 |
|
24 |
-\item{tip.order}{the order of the tips by a character vector of taxa names; or an integer, N, to order the tips by the order of the tips in the Nth tree; 'mds' to order the tips based on MDS of the path length between the tips; or 'mds_dist' to order the tips based on MDS of the distance between the tips (default: 'mds_dist')} |
|
24 |
+\item{tip.order}{the order of the tips by a character vector of taxa names; or an integer, N, to order the tips by the order of the tips in the Nth tree; 'mode' to order the tips by the most common order; 'mds' to order the tips based on MDS of the path length between the tips; or 'mds_dist' to order the tips based on MDS of the distance between the tips (default: 'mode')} |
|
25 | 25 |
|
26 | 26 |
\item{align.tips}{TRUE to align trees by their tips and FALSE to align trees by their root (default: TRUE)} |
27 | 27 |
|
... | ... |
@@ -38,40 +38,41 @@ drawing phylogenetic trees from list of phylo objects |
38 | 38 |
\examples{ |
39 | 39 |
require(ape) |
40 | 40 |
require(dplyr) |
41 |
+require(tidyr) |
|
41 | 42 |
|
42 |
-# Plot mutliple trees with aligned tips |
|
43 |
+# Plot multiple trees with aligned tips |
|
43 | 44 |
trees <- list(read.tree(text="((a:1,b:1):1.5,c:2.5);"), read.tree(text="((a:1,c:1):1,b:2);")); |
44 | 45 |
ggdensitree(trees) + geom_tiplab() |
45 | 46 |
|
46 |
-# Plot multiple trees with aligmned tips with tip labls and separate tree colors |
|
47 |
+# Plot multiple trees with aligned tips with tip labels and separate tree colors |
|
47 | 48 |
trees.fort <- list(trees[[1]] \%>\% fortify \%>\% mutate(tree="a"), trees[[2]] \%>\% fortify \%>\% mutate(tree="b")); |
48 | 49 |
ggdensitree(trees.fort, aes(colour=tree)) + geom_tiplab(colour='black') |
49 | 50 |
|
50 | 51 |
|
51 | 52 |
# Generate example data |
52 | 53 |
set.seed(1) |
53 |
-trees <- rmtree(5, 10) |
|
54 |
-time.trees <- lapply(1:length(trees), function(i) { |
|
55 |
- tree <- trees[[i]] |
|
54 |
+random.trees <- rmtree(5, 10) |
|
55 |
+time.trees <- lapply(seq_along(random.trees), function(i) { |
|
56 |
+ tree <- random.trees[[i]] |
|
56 | 57 |
tree$tip.label <- paste0("t", 1:10) |
57 | 58 |
dates <- estimate.dates(tree, 1:10, mu=1, nsteps=1) |
58 | 59 |
tree$edge.length <- dates[tree$edge[, 2]] - dates[tree$edge[, 1]] |
59 | 60 |
fortify(tree) \%>\% mutate(tree=factor(i, levels=as.character(1:10))) |
60 | 61 |
}) |
61 | 62 |
|
62 |
-# Plot multiple trees with aligned tips from muliple time points |
|
63 |
+# Plot multiple trees with aligned tips from multiple time points |
|
63 | 64 |
ggdensitree(time.trees, aes(colour=tree), tip.order=paste0("t", 1:10)) + geom_tiplab(colour='black') |
64 | 65 |
|
65 | 66 |
|
66 | 67 |
# Read example data |
67 |
-trees <- read.tree(system.file("examples", "ggdensitree_example.tree", package="ggtree")) |
|
68 |
+example.trees <- read.tree(system.file("examples", "ggdensitree_example.tree", package="ggtree")) |
|
68 | 69 |
|
69 | 70 |
# Compute OTU |
70 | 71 |
grp <- list(A = c("a.t1", "a.t2", "a.t3", "a.t4"), B = c("b.t1", "b.t2", "b.t3", "b.t4"), C = c("c.t1", "c.t2", "c.t3", "c.t4")) |
71 |
-trees <- lapply(trees, groupOTU, grp) |
|
72 |
+otu.trees <- lapply(example.trees, groupOTU, grp) |
|
72 | 73 |
|
73 | 74 |
# Plot multiple trees colored by OTU |
74 |
-ggdensitree(trees, aes(colour=group), alpha=1/6) + scale_colour_manual(values=c("black", "red", "green", "blue")) |
|
75 |
+ggdensitree(otu.trees, aes(colour=group), alpha=1/6, tip.order='mds') + scale_colour_manual(values=c("black", "red", "green", "blue")) |
|
75 | 76 |
} |
76 | 77 |
\author{ |
77 | 78 |
Yu Guangchuang, Bradley R. Jones |
... | ... |
@@ -4,8 +4,15 @@ |
4 | 4 |
\alias{ggdensitree} |
5 | 5 |
\title{ggdensitree} |
6 | 6 |
\usage{ |
7 |
-ggdensitree(data = NULL, mapping = NULL, layout = "slanted", |
|
8 |
- tip.order = "mds", align.tips = TRUE, jitter = 0, ...) |
|
7 |
+ggdensitree( |
|
8 |
+ data = NULL, |
|
9 |
+ mapping = NULL, |
|
10 |
+ layout = "slanted", |
|
11 |
+ tip.order = "mds_dist", |
|
12 |
+ align.tips = TRUE, |
|
13 |
+ jitter = 0, |
|
14 |
+ ... |
|
15 |
+) |
|
9 | 16 |
} |
10 | 17 |
\arguments{ |
11 | 18 |
\item{data}{a list of phylo objects or any object with an as.phylo and fortify method} |
... | ... |
@@ -14,7 +21,7 @@ ggdensitree(data = NULL, mapping = NULL, layout = "slanted", |
14 | 21 |
|
15 | 22 |
\item{layout}{one of 'slanted', 'rectangluar', 'fan', 'circular' or 'radial' (default: 'slanted')} |
16 | 23 |
|
17 |
-\item{tip.order}{the order of the tips by a character vector of taxa names; or an integer, N, to order the tips by the order of the tips in the Nth tree; or 'mds' to order the tips based on MDS of the distance between the tips (default: 'mds')} |
|
24 |
+\item{tip.order}{the order of the tips by a character vector of taxa names; or an integer, N, to order the tips by the order of the tips in the Nth tree; 'mds' to order the tips based on MDS of the path length between the tips; or 'mds_dist' to order the tips based on MDS of the distance between the tips (default: 'mds')} |
|
18 | 25 |
|
19 | 26 |
\item{align.tips}{TRUE to align trees by their tips and FALSE to align trees by their root (default: TRUE)} |
20 | 27 |
|
... | ... |
@@ -32,12 +39,16 @@ drawing phylogenetic trees from list of phylo objects |
32 | 39 |
require(ape) |
33 | 40 |
require(dplyr) |
34 | 41 |
|
42 |
+# Plot mutliple trees with aligned tips |
|
35 | 43 |
trees <- list(read.tree(text="((a:1,b:1):1.5,c:2.5);"), read.tree(text="((a:1,c:1):1,b:2);")); |
36 | 44 |
ggdensitree(trees) + geom_tiplab() |
37 | 45 |
|
46 |
+# Plot multiple trees with aligmned tips with tip labls and separate tree colors |
|
38 | 47 |
trees.fort <- list(trees[[1]] \%>\% fortify \%>\% mutate(tree="a"), trees[[2]] \%>\% fortify \%>\% mutate(tree="b")); |
39 | 48 |
ggdensitree(trees.fort, aes(colour=tree)) + geom_tiplab(colour='black') |
40 | 49 |
|
50 |
+ |
|
51 |
+# Generate example data |
|
41 | 52 |
set.seed(1) |
42 | 53 |
trees <- rmtree(5, 10) |
43 | 54 |
time.trees <- lapply(1:length(trees), function(i) { |
... | ... |
@@ -46,8 +57,21 @@ time.trees <- lapply(1:length(trees), function(i) { |
46 | 57 |
dates <- estimate.dates(tree, 1:10, mu=1, nsteps=1) |
47 | 58 |
tree$edge.length <- dates[tree$edge[, 2]] - dates[tree$edge[, 1]] |
48 | 59 |
fortify(tree) \%>\% mutate(tree=factor(i, levels=as.character(1:10))) |
49 |
-}) |
|
60 |
+}) |
|
61 |
+ |
|
62 |
+# Plot multiple trees with aligned tips from muliple time points |
|
50 | 63 |
ggdensitree(time.trees, aes(colour=tree), tip.order=paste0("t", 1:10)) + geom_tiplab(colour='black') |
64 |
+ |
|
65 |
+ |
|
66 |
+# Read example data |
|
67 |
+trees <- read.tree(system.file("ggtree", "inst/examples/ggdensitree_example.tree")) |
|
68 |
+ |
|
69 |
+# Compute OTU |
|
70 |
+grp <- list(A = c("a.t1", "a.t2", "a.t3", "a.t4"), B = c("b.t1", "b.t2", "b.t3", "b.t4"), C = c("c.t1", "c.t2", "c.t3", "c.t4")) |
|
71 |
+trees <- lapply(trees, groupOTU, grp) |
|
72 |
+ |
|
73 |
+# Plot multiple trees colored by OTU |
|
74 |
+ggdensitree(trees, aes(colour=group), alpha=1/6) + scale_colour_manual(values=c("black", "red", "green", "blue")) |
|
51 | 75 |
} |
52 | 76 |
\author{ |
53 | 77 |
Yu Guangchuang, Bradley R. Jones |
... | ... |
@@ -4,8 +4,15 @@ |
4 | 4 |
\alias{ggdensitree} |
5 | 5 |
\title{ggdensitree} |
6 | 6 |
\usage{ |
7 |
-ggdensitree(data = NULL, mapping = NULL, layout = "slanted", |
|
8 |
- tip.order = "mds", align.tips = TRUE, jitter = 0, ...) |
|
7 |
+ggdensitree( |
|
8 |
+ data = NULL, |
|
9 |
+ mapping = NULL, |
|
10 |
+ layout = "slanted", |
|
11 |
+ tip.order = "mds", |
|
12 |
+ align.tips = TRUE, |
|
13 |
+ jitter = 0, |
|
14 |
+ ... |
|
15 |
+) |
|
9 | 16 |
} |
10 | 17 |
\arguments{ |
11 | 18 |
\item{data}{a list of phylo objects or any object with an as.phylo and fortify method} |
... | ... |
@@ -5,8 +5,7 @@ |
5 | 5 |
\title{ggdensitree} |
6 | 6 |
\usage{ |
7 | 7 |
ggdensitree(data = NULL, mapping = NULL, layout = "slanted", |
8 |
- branch.length = "none", tip.order = "mds", dangle = TRUE, |
|
9 |
- jitter = 0, ...) |
|
8 |
+ tip.order = "mds", align.tips = TRUE, jitter = 0, ...) |
|
10 | 9 |
} |
11 | 10 |
\arguments{ |
12 | 11 |
\item{data}{a list of phylo objects or any object with an as.phylo and fortify method} |
... | ... |
@@ -15,11 +14,9 @@ ggdensitree(data = NULL, mapping = NULL, layout = "slanted", |
15 | 14 |
|
16 | 15 |
\item{layout}{one of 'slanted', 'rectangluar', 'fan', 'circular' or 'radial' (default: 'slanted')} |
17 | 16 |
|
18 |
-\item{branch.length}{variable to be used to scale branch length. Setting to 'branch.length' will use the branch lengths of the tree objects. Default is 'none' to discard branch length and only plot cladogram (more reasonable for densitree).} |
|
19 |
- |
|
20 | 17 |
\item{tip.order}{the order of the tips by a character vector of taxa names; or an integer, N, to order the tips by the order of the tips in the Nth tree; or 'mds' to order the tips based on MDS of the distance between the tips (default: 'mds')} |
21 | 18 |
|
22 |
-\item{dangle}{TRUE to align trees by their tips and FALSE to align treesby their root (default: TRUE)} |
|
19 |
+\item{align.tips}{TRUE to align trees by their tips and FALSE to align trees by their root (default: TRUE)} |
|
23 | 20 |
|
24 | 21 |
\item{jitter}{deviation to jitter tips} |
25 | 22 |
|
... | ... |
@@ -34,13 +31,23 @@ drawing phylogenetic trees from list of phylo objects |
34 | 31 |
\examples{ |
35 | 32 |
require(ape) |
36 | 33 |
require(dplyr) |
37 |
-library(ape) |
|
38 | 34 |
|
39 |
-trees <- list(read.tree(text="((a,b),c);"), read.tree(text="((a,c),b);")); |
|
35 |
+trees <- list(read.tree(text="((a:1,b:1):1.5,c:2.5);"), read.tree(text="((a:1,c:1):1,b:2);")); |
|
40 | 36 |
ggdensitree(trees) + geom_tiplab() |
41 | 37 |
|
42 | 38 |
trees.fort <- list(trees[[1]] \%>\% fortify \%>\% mutate(tree="a"), trees[[2]] \%>\% fortify \%>\% mutate(tree="b")); |
43 | 39 |
ggdensitree(trees.fort, aes(colour=tree)) + geom_tiplab(colour='black') |
40 |
+ |
|
41 |
+set.seed(1) |
|
42 |
+trees <- rmtree(5, 10) |
|
43 |
+time.trees <- lapply(1:length(trees), function(i) { |
|
44 |
+ tree <- trees[[i]] |
|
45 |
+ tree$tip.label <- paste0("t", 1:10) |
|
46 |
+ dates <- estimate.dates(tree, 1:10, mu=1, nsteps=1) |
|
47 |
+ tree$edge.length <- dates[tree$edge[, 2]] - dates[tree$edge[, 1]] |
|
48 |
+ fortify(tree) \%>\% mutate(tree=factor(i, levels=as.character(1:10))) |
|
49 |
+}) |
|
50 |
+ggdensitree(time.trees, aes(colour=tree), tip.order=paste0("t", 1:10)) + geom_tiplab(colour='black') |
|
44 | 51 |
} |
45 | 52 |
\author{ |
46 | 53 |
Yu Guangchuang, Bradley R. Jones |
... | ... |
@@ -5,7 +5,8 @@ |
5 | 5 |
\title{ggdensitree} |
6 | 6 |
\usage{ |
7 | 7 |
ggdensitree(data = NULL, mapping = NULL, layout = "slanted", |
8 |
- tip.order = "mds", dangle = TRUE, jitter = 0, ...) |
|
8 |
+ branch.length = "none", tip.order = "mds", dangle = TRUE, |
|
9 |
+ jitter = 0, ...) |
|
9 | 10 |
} |
10 | 11 |
\arguments{ |
11 | 12 |
\item{data}{a list of phylo objects or any object with an as.phylo and fortify method} |
... | ... |
@@ -14,6 +15,8 @@ ggdensitree(data = NULL, mapping = NULL, layout = "slanted", |
14 | 15 |
|
15 | 16 |
\item{layout}{one of 'slanted', 'rectangluar', 'fan', 'circular' or 'radial' (default: 'slanted')} |
16 | 17 |
|
18 |
+\item{branch.length}{variable to be used to scale branch length. Setting to 'branch.length' will use the branch lengths of the tree objects. Default is 'none' to discard branch length and only plot cladogram (more reasonable for densitree).} |
|
19 |
+ |
|
17 | 20 |
\item{tip.order}{the order of the tips by a character vector of taxa names; or an integer, N, to order the tips by the order of the tips in the Nth tree; or 'mds' to order the tips based on MDS of the distance between the tips (default: 'mds')} |
18 | 21 |
|
19 | 22 |
\item{dangle}{TRUE to align trees by their tips and FALSE to align treesby their root (default: TRUE)} |
... | ... |
@@ -32,7 +35,6 @@ drawing phylogenetic trees from list of phylo objects |
32 | 35 |
require(ape) |
33 | 36 |
require(dplyr) |
34 | 37 |
library(ape) |
35 |
-library(tidyverse) |
|
36 | 38 |
|
37 | 39 |
trees <- list(read.tree(text="((a,b),c);"), read.tree(text="((a,c),b);")); |
38 | 40 |
ggdensitree(trees) + geom_tiplab() |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,45 @@ |
1 |
+% Generated by roxygen2: do not edit by hand |
|
2 |
+% Please edit documentation in R/ggdensitree.R |
|
3 |
+\name{ggdensitree} |
|
4 |
+\alias{ggdensitree} |
|
5 |
+\title{ggdensitree} |
|
6 |
+\usage{ |
|
7 |
+ggdensitree(data = NULL, mapping = NULL, layout = "slanted", |
|
8 |
+ tip.order = "mds", dangle = TRUE, jitter = 0, ...) |
|
9 |
+} |
|
10 |
+\arguments{ |
|
11 |
+\item{data}{a list of phylo objects or any object with an as.phylo and fortify method} |
|
12 |
+ |
|
13 |
+\item{mapping}{aesthetic mapping} |
|
14 |
+ |
|
15 |
+\item{layout}{one of 'slanted', 'rectangluar', 'fan', 'circular' or 'radial' (default: 'slanted')} |
|
16 |
+ |
|
17 |
+\item{tip.order}{the order of the tips by a character vector of taxa names; or an integer, N, to order the tips by the order of the tips in the Nth tree; or 'mds' to order the tips based on MDS of the distance between the tips (default: 'mds')} |
|
18 |
+ |
|
19 |
+\item{dangle}{TRUE to align trees by their tips and FALSE to align treesby their root (default: TRUE)} |
|
20 |
+ |
|
21 |
+\item{jitter}{deviation to jitter tips} |
|
22 |
+ |
|
23 |
+\item{...}{additional parameters passed to fortify, ggtree and geom_tree} |
|
24 |
+} |
|
25 |
+\value{ |
|
26 |
+tree layer |
|
27 |
+} |
|
28 |
+\description{ |
|
29 |
+drawing phylogenetic trees from list of phylo objects |
|
30 |
+} |
|
31 |
+\examples{ |
|
32 |
+require(ape) |
|
33 |
+require(dplyr) |
|
34 |
+library(ape) |
|
35 |
+library(tidyverse) |
|
36 |
+ |
|
37 |
+trees <- list(read.tree(text="((a,b),c);"), read.tree(text="((a,c),b);")); |
|
38 |
+ggdensitree(trees) + geom_tiplab() |
|
39 |
+ |
|
40 |
+trees.fort <- list(trees[[1]] \%>\% fortify \%>\% mutate(tree="a"), trees[[2]] \%>\% fortify \%>\% mutate(tree="b")); |
|
41 |
+ggdensitree(trees.fort, aes(colour=tree)) + geom_tiplab(colour='black') |
|
42 |
+} |
|
43 |
+\author{ |
|
44 |
+Yu Guangchuang, Bradley R. Jones |
|
45 |
+} |