Skip to content

Commit

Permalink
Merge pull request #124 from JustGitting/master
Browse files Browse the repository at this point in the history
Add "daylight" layout method for unrooted trees.
  • Loading branch information
GuangchuangYu authored Apr 10, 2017
2 parents 6c3d0a2 + fb2b245 commit 3f54202
Show file tree
Hide file tree
Showing 5 changed files with 731 additions and 76 deletions.
5 changes: 5 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ mkdocs
docs
logo.png.github
.github
<<<<<<< HEAD
^.*\.Rproj$
^\.Rproj\.user$
=======
ggtree_sticker.R
>>>>>>> 6c3d0a213ebba123a58af768ef6d7b4ec93b85d1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ __init__.py
__pycache__
__init__.pyc

.Rproj.user
ggtree.Rproj
.RData
11 changes: 9 additions & 2 deletions R/ggtree.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
##' @param tr phylo object
##' @param mapping aes mapping
##' @param layout one of 'rectangular', 'slanted', 'fan', 'circular', 'radial' or 'unrooted'
##' @param layout.method of 'equal_angle', 'daylight'.
##' @param open.angle open angle, only for 'fan' layout
##' @param mrsd most recent sampling date
##' @param as.Date logical whether using Date class in time tree
Expand Down Expand Up @@ -33,6 +34,7 @@
ggtree <- function(tr,
mapping = NULL,
layout = "rectangular",
layout.method = "equal_angle",
open.angle = 0,
mrsd = NULL,
as.Date = FALSE,
Expand All @@ -44,8 +46,10 @@ ggtree <- function(tr,
ndigits = NULL,
...) {

# Check if layout string is valid.
layout %<>% match.arg(c("rectangular", "slanted", "fan", "circular", "radial", "unrooted"))

layout.method %<>% match.arg(c("equal_angle", "daylight"))

if (is(tr, "r8s") && branch.length == "branch.length") {
branch.length = "TREE"
}
Expand All @@ -60,8 +64,11 @@ ggtree <- function(tr,
} else {
mapping <- modifyList(aes_(~x, ~y), mapping)
}
p <- ggplot(tr, mapping=mapping,

p <- ggplot(tr,
mapping = mapping,
layout = layout,
layout.method = layout.method,
mrsd = mrsd,
as.Date = as.Date,
yscale = yscale,
Expand Down
75 changes: 55 additions & 20 deletions R/method-fortify.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ rm.singleton.newick <- function(nwk, outfile = NULL) {
##' @export
fortify.beast <- function(model, data,
layout = "rectangular",
layout.method = "equal_angle",
yscale = "none",
ladderize = TRUE,
right = FALSE,
Expand All @@ -119,7 +120,8 @@ fortify.beast <- function(model, data,

model <- set_branch_length(model, branch.length)
phylo <- model@phylo
df <- fortify(phylo, layout=layout, branch.length=branch.length,
df <- fortify(phylo, layout=layout, layout.method=layout.method,
branch.length=branch.length,
ladderize=ladderize, right=right, mrsd = mrsd, ...)

stats <- model@stats
Expand Down Expand Up @@ -220,6 +222,7 @@ fortify.beast <- function(model, data,
##' @export
fortify.codeml <- function(model, data,
layout = "rectangular",
layout.method = "equal_angle",
yscale = "none",
ladderize = TRUE,
right = FALSE,
Expand Down Expand Up @@ -265,6 +268,7 @@ fortify.codeml <- function(model, data,
##' @export
fortify.codeml_mlc <- function(model, data,
layout = "rectangular",
layout.method = "equal_angle",
yscale = "none",
ladderize = TRUE,
right = FALSE,
Expand Down Expand Up @@ -306,6 +310,7 @@ merge_phylo_anno.codeml_mlc <- function(df, dNdS, ndigits = NULL) {

fortify.codeml_mlc_ <- function(model, data,
layout = "rectangular",
layout.method = "equal_angle",
ladderize = TRUE,
right = FALSE,
branch.length = "branch.length",
Expand All @@ -317,8 +322,12 @@ fortify.codeml_mlc_ <- function(model, data,

##' @method fortify paml_rst
##' @export
fortify.paml_rst <- function(model, data, layout = "rectangular", yscale="none",
ladderize=TRUE, right=FALSE, mrsd=NULL, ...) {
fortify.paml_rst <- function(model, data,
layout = "rectangular",
yscale="none",
ladderize=TRUE,
right=FALSE,
mrsd=NULL, ...) {
df <- fortify.phylo(model@phylo, data, layout, ladderize, right, mrsd=mrsd, ...)
df <- merge_phylo_anno.paml_rst(df, model)
df <- scaleY(model@phylo, df, yscale, layout, ...)
Expand Down Expand Up @@ -353,8 +362,11 @@ fortify.hyphy <- fortify.paml_rst
##' @importFrom treeio get.placements
##' @export
fortify.jplace <- function(model, data,
layout="rectangular", yscale="none",
ladderize=TRUE, right=FALSE, mrsd=NULL, ...) {
layout="rectangular",
yscale="none",
ladderize=TRUE,
right=FALSE,
mrsd=NULL, ...) {
df <- extract.treeinfo.jplace(model, layout, ladderize, right, mrsd=mrsd, ...)
place <- get.placements(model, by="best")

Expand Down Expand Up @@ -403,8 +415,13 @@ fortify.phylo4 <- function(model, data, layout="rectangular", yscale="none",

##' @method fortify phylo4d
##' @export
fortify.phylo4d <- function(model, data, layout="rectangular", yscale="none",
ladderize=TRUE, right=FALSE, branch.length="branch.length",
fortify.phylo4d <- function(model, data,
layout="rectangular",
layout.method = "equal_angle",
yscale="none",
ladderize=TRUE,
right=FALSE,
branch.length="branch.length",
mrsd=NULL, ...) {
## model <- set_branch_length(model, branch.length)
## phylo <- as.phylo.phylo4(model)
Expand All @@ -413,7 +430,7 @@ fortify.phylo4d <- function(model, data, layout="rectangular", yscale="none",
## tdata <- model@data[match(res$node, rownames(model@data)), , drop=FALSE]
## df <- cbind(res, tdata)
## scaleY(as.phylo.phylo4(model), df, yscale, layout, ...)
fortify(as.treedata(model), data, layout, yscale, ladderize, right, branch.length, mrsd, ...)
fortify(as.treedata(model), data, layout, layout.method, yscale, ladderize, right, branch.length, mrsd, ...)
}


Expand All @@ -438,8 +455,12 @@ fortify.phylo4d <- function(model, data, layout="rectangular", yscale="none",
##' @method fortify phylo
##' @export
##' @author Yu Guangchuang
fortify.phylo <- function(model, data, layout="rectangular",
ladderize=TRUE, right=FALSE, mrsd=NULL, as.Date=FALSE, ...) {
fortify.phylo <- function(model, data,
layout="rectangular",
ladderize=TRUE,
right=FALSE,
mrsd=NULL,
as.Date=FALSE, ...) {
tree <- reorder.phylo(model, 'postorder')

if (ladderize == TRUE) {
Expand Down Expand Up @@ -605,18 +626,26 @@ fortify.multiPhylo <- function(model, data, layout="rectangular",

##' @method fortify phylip
##' @export
fortify.phylip <- function(model, data, layout="rectangular",
ladderize=TRUE, right=FALSE,
branch.length = "TREE", mrsd=NULL, ...) {
fortify.phylip <- function(model, data,
layout="rectangular",
layout.method = "equal_angle",
ladderize=TRUE,
right=FALSE,
branch.length = "TREE",
mrsd=NULL, ...) {
trees <- get.tree(model)
fortify(trees, layout=layout, ladderize = ladderize, right=right, mrsd=mrsd, ...)
}

##' @method fortify r8s
##' @export
fortify.r8s <- function(model, data, layout="rectangular",
ladderize=TRUE, right=FALSE,
branch.length = "TREE", mrsd=NULL, ...) {
fortify.r8s <- function(model, data,
layout="rectangular",
layout.method = "equal_angle",
ladderize=TRUE,
right=FALSE,
branch.length = "TREE",
mrsd=NULL, ...) {
trees <- get.tree(model)
branch.length %<>% match.arg(names(trees))
phylo <- trees[[branch.length]]
Expand All @@ -625,8 +654,11 @@ fortify.r8s <- function(model, data, layout="rectangular",

##' @method fortify obkData
##' @export
fortify.obkData <- function(model, data, layout="rectangular",
ladderize=TRUE, right=FALSE, mrsd = NULL, ...) {
fortify.obkData <- function(model, data,
layout="rectangular",
ladderize=TRUE,
right=FALSE,
mrsd = NULL, ...) {

df <- fortify(model@trees[[1]], layout=layout, ladderize=ladderize, right=right, mrsd=mrsd, ...)

Expand All @@ -644,8 +676,11 @@ fortify.obkData <- function(model, data, layout="rectangular",

##' @method fortify phyloseq
##' @export
fortify.phyloseq <- function(model, data, layout="rectangular",
ladderize=TRUE, right=FALSE, mrsd=NULL, ...) {
fortify.phyloseq <- function(model, data,
layout="rectangular",
ladderize=TRUE,
right=FALSE,
mrsd=NULL, ...) {

df <- fortify(model@phy_tree, layout=layout, ladderize=ladderize, right=right, mrsd=mrsd, ...)
phyloseq <- "phyloseq"
Expand Down
Loading

0 comments on commit 3f54202

Please sign in to comment.