man/ggdensitree.Rd
a88f71ef
 % Generated by roxygen2: do not edit by hand
 % Please edit documentation in R/ggdensitree.R
 \name{ggdensitree}
 \alias{ggdensitree}
 \title{ggdensitree}
 \usage{
1ba3cd01
 ggdensitree(
   data = NULL,
   mapping = NULL,
   layout = "slanted",
   tip.order = "mds_dist",
   align.tips = TRUE,
   jitter = 0,
   ...
 )
a88f71ef
 }
 \arguments{
 \item{data}{a list of phylo objects or any object with an as.phylo and fortify method}
 
 \item{mapping}{aesthetic mapping}
 
 \item{layout}{one of 'slanted', 'rectangluar', 'fan', 'circular' or 'radial' (default: 'slanted')}
 
e201d4b9
 \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')}
a88f71ef
 
7a94bf43
 \item{align.tips}{TRUE to align trees by their tips and FALSE to align trees by their root (default: TRUE)}
a88f71ef
 
 \item{jitter}{deviation to jitter tips}
 
 \item{...}{additional parameters passed to fortify, ggtree and geom_tree}
 }
 \value{
 tree layer
 }
 \description{
 drawing phylogenetic trees from list of phylo objects
 }
 \examples{
 require(ape)
 require(dplyr)
 
1ba3cd01
 # Plot mutliple trees with aligned tips
7a94bf43
 trees <- list(read.tree(text="((a:1,b:1):1.5,c:2.5);"), read.tree(text="((a:1,c:1):1,b:2);"));
a88f71ef
 ggdensitree(trees) + geom_tiplab()
 
1ba3cd01
 # Plot multiple trees with aligmned tips with tip labls and separate tree colors
a88f71ef
 trees.fort <- list(trees[[1]] \%>\% fortify \%>\% mutate(tree="a"), trees[[2]] \%>\% fortify \%>\% mutate(tree="b"));
 ggdensitree(trees.fort, aes(colour=tree)) + geom_tiplab(colour='black')
7a94bf43
 
1ba3cd01
 
 # Generate example data
7a94bf43
 set.seed(1)
 trees <- rmtree(5, 10)
 time.trees <- lapply(1:length(trees), function(i) {
  	tree <- trees[[i]]
  	tree$tip.label <- paste0("t", 1:10)
 	dates <- estimate.dates(tree, 1:10, mu=1, nsteps=1)
 	tree$edge.length <- dates[tree$edge[, 2]] - dates[tree$edge[, 1]]
 	fortify(tree) \%>\% mutate(tree=factor(i, levels=as.character(1:10)))
1ba3cd01
 })
 
 # Plot multiple trees with aligned tips from muliple time points
7a94bf43
 ggdensitree(time.trees, aes(colour=tree), tip.order=paste0("t", 1:10)) + geom_tiplab(colour='black')
1ba3cd01
 
 
 # Read example data
e201d4b9
 trees <- read.tree(system.file("examples", "ggdensitree_example.tree", package="ggtree"))
1ba3cd01
 
 # Compute OTU
 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"))
 trees <- lapply(trees, groupOTU, grp)
 
 # Plot multiple trees colored by OTU
 ggdensitree(trees, aes(colour=group), alpha=1/6) + scale_colour_manual(values=c("black", "red", "green", "blue"))
a88f71ef
 }
 \author{
 Yu Guangchuang, Bradley R. Jones
 }