├── DESCRIPTION ├── NAMESPACE ├── R ├── allChecks.R ├── formatTree.R ├── phylo_species-data.R ├── phylo_tree-data.R ├── spdata-data.R └── treeAndLeaf.R ├── README.md ├── build └── vignette.rds ├── data ├── phylo_species.RData ├── phylo_tree.RData └── spdata.RData ├── inst ├── NEWS.Rd ├── doc │ ├── TreeAndLeaf.R │ ├── TreeAndLeaf.Rmd │ └── TreeAndLeaf.html └── unitTests │ └── test_tal.R ├── man ├── TreeAndLeaf-package.Rd ├── formatTree.Rd ├── phylo_species.Rd ├── phylo_tree.Rd ├── spdata.Rd └── treeAndLeaf.Rd ├── tests └── runTests.R └── vignettes ├── PhyloPurple.png ├── QuakesTree.png ├── TreeAndLeaf.Rmd ├── USAReds.png ├── custom.css ├── ggtree_tal.png ├── nBinPhylo.png └── overview.png /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: TreeAndLeaf 2 | Type: Package 3 | Title: Displaying binary trees with focus on dendrogram leaves 4 | Version: 1.5.3 5 | Description: The TreeAndLeaf package combines unrooted and force-directed graph algorithms in order to layout binary trees, aiming to represent multiple layers of information onto dendrogram leaves. 6 | Author: Leonardo W. Kume, Luis E. A. Rizzardi, Milena A. Cardoso, Mauro A. A. Castro 7 | Maintainer: Milena A. Cardoso 8 | Depends: R(>= 4.0) 9 | Imports: RedeR(>= 1.40.4), igraph, ape 10 | Suggests: knitr, rmarkdown, BiocStyle, RUnit, BiocGenerics, stringr, 11 | geneplast, ggtree, ggplot2, dplyr, dendextend, RColorBrewer 12 | License: Artistic-2.0 13 | Encoding: UTF-8 14 | RoxygenNote: 7.1.1 15 | VignetteBuilder: knitr 16 | biocViews: Infrastructure, GraphAndNetwork, Software, Network, 17 | Visualization, DataRepresentation 18 | NeedsCompilation: no 19 | Packaged: 2021-08-28 15:56:06 UTC; maac 20 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(formatTree) 4 | export(treeAndLeaf) 5 | importFrom(RedeR,RedPort) 6 | importFrom(ape,as.igraph.phylo) 7 | importFrom(ape,as.phylo) 8 | importFrom(igraph,'E<-') 9 | importFrom(igraph,'V<-') 10 | importFrom(igraph,E) 11 | importFrom(igraph,V) 12 | importFrom(igraph,edge_betweenness) 13 | importFrom(igraph,is.igraph) 14 | -------------------------------------------------------------------------------- /R/allChecks.R: -------------------------------------------------------------------------------- 1 | ##This function is used for argument checking 2 | tal.checks <- function(name, para){ 3 | if(identical(name, "tal")) { 4 | if(!is.tal(para)){ 5 | stop("'tal' must be an 'igraph' object created by the 6 | TreeAndLeaf() function!", call.=FALSE) 7 | } 8 | } else if(identical(name, "theme")){ 9 | if(!is.singleInteger(para) || para > 5 || para < 1){ 10 | stop("'theme' must be an integer ranging from 1 to 5!", 11 | call.=FALSE) 12 | } 13 | } else if(identical(name, "obj")){ 14 | if (!any(class(para)%in%c("hclust","phylo","ggtree"))) 15 | stop("'obj' must be a 'hclust', 'phylo', or 'ggtree' objects!", 16 | call.=FALSE) 17 | } else { 18 | stop("'name' option not available!", call.=FALSE) 19 | } 20 | } 21 | 22 | ##------------------------------------------------------------------------------ 23 | is.tal <- function(para){ 24 | "tal" %in% class(para) 25 | } 26 | is.singleInteger <- function(para){ 27 | lg <- (is.integer(para) || is.numeric(para)) && length(para)==1L && 28 | !is.na(para) 29 | if(lg) lg <- (para / ceiling(para)) == 1 30 | return(lg) 31 | } 32 | is.singleString <- function(para){ 33 | is.character(para) && length(para) == 1L && !is.na(para) 34 | } 35 | is.singleLogical <- function(para){ 36 | is.logical(para) && length(para) == 1L && !is.na(para) 37 | } 38 | -------------------------------------------------------------------------------- /R/formatTree.R: -------------------------------------------------------------------------------- 1 | #' A theme function for tree-and-leaf igraph objects. 2 | #' 3 | #' This function sets attributes of a tree-and-leaf igraph object for 4 | #' plotting in the RedeR app interface. 5 | #' 6 | #' @param tal An igraph object generated by the \code{\link{TreeAndLeaf}} function. 7 | #' @param theme An integer ranging from 1 to 5 with desired theme. \cr 8 | #' Options: \cr 9 | #' 1- A clean black and blue theme, for additional customizations. \cr 10 | #' 2- Green palette theme. \cr 11 | #' 3- Blue palette theme. \cr 12 | #' 4- Purple palette theme. \cr 13 | #' 5- Red palette theme. \cr 14 | #' For detailed customization, see attributes in the 15 | #' \code{\link[RedeR]{addGraph}} method. \cr 16 | #' 17 | #' @return An igraph object with attributes for RedeR application. 18 | #' 19 | #' @seealso \code{\link[RedeR]{addGraph}} 20 | #' @seealso \code{\link{treeAndLeaf}} 21 | #' 22 | #' @examples 23 | #' library(RedeR) 24 | #' hc <- hclust(dist(USArrests), "ave") 25 | #' tal <- treeAndLeaf(hc) 26 | #' tal <- formatTree(tal, theme = 5) 27 | #' 28 | #' @importFrom igraph V E 29 | #' @export 30 | 31 | formatTree <- function(tal, theme = 1){ 32 | tal.checks(name = "tal", para = tal) 33 | tal.checks(name = "theme", para = theme) 34 | tal <- .setSizeTheme(tal) 35 | tal <- .setColorTheme(tal, theme) 36 | return(tal) 37 | } 38 | #------------------------------------------------------------------------------- 39 | .setSizeTheme <- function(tal){ 40 | sz <- sum(V(tal)$isLeaf) 41 | sz <- sqrt(sz) 42 | igraph::V(tal)$nodeFontSize <- ceiling(min(max(15,sz),75)) 43 | igraph::V(tal)$nodeFontSize[!V(tal)$isLeaf] <- 1 44 | igraph::V(tal)$nodeSize <- ceiling(min(max(15,sz),100)) 45 | igraph::V(tal)$nodeSize[!V(tal)$isLeaf] <- ceiling(min(max(5,sz/6),15)) 46 | igraph::E(tal)$edgeWidth <- ceiling(min(max(15,sz/2),50)) 47 | igraph::V(tal)$nodeLineWidth <- ceiling(min(max(5,sz/2),20)) 48 | return(tal) 49 | } 50 | #------------------------------------------------------------------------------- 51 | .setColorTheme <- function(tal, theme){ 52 | #Set node line color 53 | switch (theme, 54 | igraph::V(tal)$nodeLineColor <- "#000000", 55 | igraph::V(tal)$nodeLineColor <- "#379683", 56 | igraph::V(tal)$nodeLineColor <- "#55CFD1", 57 | igraph::V(tal)$nodeLineColor <- "#7F61A5", 58 | igraph::V(tal)$nodeLineColor <- "#D4A59A") 59 | #Set node font color 60 | switch (theme, 61 | igraph::V(tal)$nodeFontColor <- "#000000", 62 | igraph::V(tal)$nodeFontColor <- "#05386B", 63 | igraph::V(tal)$nodeFontColor <- "#1F2833", 64 | igraph::V(tal)$nodeFontColor <- "#5C2018", 65 | igraph::V(tal)$nodeFontColor <- "#5C2018") 66 | #Set the edge color 67 | switch (theme, 68 | igraph::E(tal)$edgeColor <- "#000000", 69 | igraph::E(tal)$edgeColor <- "#379683", 70 | igraph::E(tal)$edgeColor <- "#55CFD1", 71 | igraph::E(tal)$edgeColor <- "#7F61A5", 72 | igraph::E(tal)$edgeColor <- "#D4A59A") 73 | #Set the node colors 74 | switch (theme, 75 | igraph::V(tal)$nodeColor <- "#190061", 76 | igraph::V(tal)$nodeColor <- "#5CDB95", 77 | igraph::V(tal)$nodeColor <- "#45A29E", 78 | igraph::V(tal)$nodeColor <- "#44318D", 79 | igraph::V(tal)$nodeColor <- "#BC4639") 80 | return(tal) 81 | } 82 | -------------------------------------------------------------------------------- /R/phylo_species-data.R: -------------------------------------------------------------------------------- 1 | #' Species metadata from STRING-db v11 2 | #' 3 | #' Species metadata used in a phylo object. 4 | #' 5 | #' @docType data 6 | #' 7 | #' @name phylo_species 8 | #' 9 | #' @usage data(phylo_species) 10 | #' 11 | #' @format An object of class \code{"data.frame"} 12 | #' 13 | #' @keywords datasets 14 | #' 15 | #' @references 16 | #' Szklarczyk D. et al. STRING v11: protein-protein association networks with 17 | #' increased coverage, supporting functional discovery in genome-wide 18 | #' experimental datasets. Nucleic Acids Res. 47:D607-613, 2019. 19 | #' 20 | NULL -------------------------------------------------------------------------------- /R/phylo_tree-data.R: -------------------------------------------------------------------------------- 1 | #' Species tree from STRING-db v11 2 | #' 3 | #' A phylo object for the species tree available from the STRING-db v11. 4 | #' 5 | #' @docType data 6 | #' 7 | #' @name phylo_tree 8 | #' 9 | #' @usage data(phylo_tree) 10 | #' 11 | #' @format An object of class \code{"phylo"} 12 | #' 13 | #' @keywords phylotree 14 | #' 15 | #' @references 16 | #' Szklarczyk D. et al. STRING v11: protein-protein association networks with 17 | #' increased coverage, supporting functional discovery in genome-wide 18 | #' experimental datasets. Nucleic Acids Res. 47:D607-613, 2019. 19 | 20 | #' 21 | NULL -------------------------------------------------------------------------------- /R/spdata-data.R: -------------------------------------------------------------------------------- 1 | #' Genome statistics for eukaryotes with complete genome sequence 2 | #' 3 | #' Data from the NCBI Genome Database for eukaryotes with complete genome sequence. 4 | #' The list of organisms were obtained from the KEGG Organisms Database, and 5 | #' taxonomy IDs were obtained from the NCBI Taxonomy Database. 6 | #' 7 | #' @docType data 8 | #' 9 | #' @name spdata 10 | #' 11 | #' @usage data(spdata) 12 | #' 13 | #' @format An object of class \code{"data.frame"} 14 | #' 15 | #' @keywords datasets 16 | #' 17 | #' @references 18 | #' NCBI Genome Database 19 | #' https://www.ncbi.nlm.nih.gov/genome 20 | #' Accessed: August 15, 2019. 21 | #' 22 | #' NCBI Taxonomy Database 23 | #' https://www.ncbi.nlm.nih.gov/taxonomy 24 | #' Accessed: August 15, 2019. 25 | #' 26 | #' KEGG Organisms Database 27 | #' https://www.genome.jp/kegg/catalog/org_list.html 28 | #' Accessed: August 15, 2019. 29 | #' 30 | #' @examples 31 | #' data(spdata) 32 | NULL -------------------------------------------------------------------------------- /R/treeAndLeaf.R: -------------------------------------------------------------------------------- 1 | #' Layout a TreeAndLeaf diagram. 2 | #' 3 | #' This function tranforms hclust and phylo objects into tree-and-leaf 4 | #' igraph objects. 5 | #' 6 | #' @param obj An object of class 'hclust' or 'phylo'. 7 | #' 8 | #' @return A tree-and-leaf igraph object. 9 | #' 10 | #' @seealso \code{\link{formatTree}} 11 | #' @seealso \code{\link[stats:hclust]{hclust}} 12 | #' @seealso \code{\link[ape:as.phylo]{as.phylo}} 13 | #' @seealso \code{\link[RedeR:addGraph]{addGraph}} 14 | #' @seealso \code{\link[RedeR:relax]{relax}} 15 | #' 16 | #' @examples 17 | #' library(RedeR) 18 | #' rdp <- RedPort() 19 | #' hc <- hclust(dist(USArrests), "ave") 20 | #' tal <- treeAndLeaf(hc) 21 | #' 22 | #' \dontrun{ 23 | #' calld(rdp) 24 | #' addGraph(obj=rdp, tal) 25 | #' } 26 | #' 27 | #' @importFrom igraph edge_betweenness is.igraph V E 'V<-' 'E<-' 28 | #' @importFrom ape as.phylo as.igraph.phylo 29 | #' @importFrom RedeR RedPort 30 | #' @export 31 | 32 | treeAndLeaf <- function(obj){ 33 | tal.checks(name="obj", para=obj) 34 | tal <- .setTaL(obj) 35 | return(tal) 36 | } 37 | # resetd(rdp) 38 | # addGraph(rdp, tal) 39 | #------------------------------------------------------------------------------- 40 | .setTaL <- function(obj){ 41 | if ("hclust" %in% class(obj)){ 42 | phylo <- ape::as.phylo(obj) 43 | gg <- ape::as.igraph.phylo(phylo, directed=FALSE) 44 | coords <- .get.tree.coords(phylo, use.edge.length=FALSE) 45 | } else if("phylo" %in% class(obj)){ 46 | gg <- ape::as.igraph.phylo(obj, directed=FALSE) 47 | coords <- .get.tree.coords(obj, use.edge.length=FALSE) 48 | } else if("ggtree" %in% class(obj)){ 49 | lpar <- obj$layers[[1]]$stat_params$layout 50 | vpar <- c("daylight","ape","fan","equal_angle") 51 | if(!lpar%in%vpar) 52 | stop("Please, use one of the 'ggtree' layouts: ", 53 | paste0(vpar, collapse = ", "),"!", call.=FALSE) 54 | # gdata <- ggplot_build(obj)$data[[1]] 55 | phylo <- ape::as.phylo(obj$data) 56 | gg <- ape::as.igraph.phylo(phylo, directed=FALSE) 57 | coords <- .get.tree.coords(phylo, use.edge.length=FALSE) 58 | coords$layout[,] <- as.matrix(obj$data[,c("x","y")]) 59 | } 60 | if(!all(V(gg)$name%in%rownames(coords$layout))) 61 | stop("An unexpected error occurred while transforming the graph object!") 62 | #--- set layout 63 | layout <- coords$layout[V(gg)$name,] 64 | V(gg)$coordX <- layout[,"x"] 65 | V(gg)$coordY <- layout[,"y"] 66 | V(gg)$isLeaf <- V(gg)$name%in%coords$phylo$tip.label 67 | gg$centralVertex <- coords$centralVertex 68 | #--- set edge weights 69 | E(gg)$weight <- 0.01 70 | bt <- igraph::edge_betweenness(gg, directed = T) 71 | bt <- (1 - bt/max(bt)) 72 | E(gg)$weight <- bt 73 | #--- set node and font sizes 74 | V(gg)$nodeAlias <- V(gg)$name 75 | V(gg)$nodeSize <- 5 76 | V(gg)$nodeSize[V(gg)$isLeaf] <- 30 77 | V(gg)$nodeFontSize <- 15 78 | V(gg)$nodeFontSize[!V(gg)$isLeaf] <- 1 79 | V(gg)$nodeColor <- "#ffcccc" 80 | V(gg)$nodeLineColor <- "#9999ff" 81 | V(gg)$nodeLineWidth <- 2 82 | E(gg)$edgeColor <- "#9999ff" 83 | E(gg)$edgeWidth <- 2 84 | #--- set zoom 85 | sz <- sum(V(gg)$isLeaf) 86 | sz <- sqrt(sz) 87 | # gg$zoom <- ceiling(max(0,100-sz)) 88 | gg$gtype <- "TreeAndLeaf" 89 | class(gg) <- c("tal","igraph") 90 | return(gg) 91 | } 92 | 93 | #------------------------------------------------------------------------------- 94 | # This function gets coordinates from an unrooted 'phylo' objects, 95 | # derived from a currectly not exported function from the ape package 96 | .get.tree.coords <- function(phy, use.edge.length = FALSE){ 97 | if (is.null(phy$edge.length)) use.edge.length <- FALSE 98 | phy <- ape::reorder.phylo(phy) 99 | Ntip <- length(phy$tip.label) 100 | Nedge <- dim(phy$edge)[1] 101 | Nnode <- phy$Nnode 102 | nb.sp <- ape::node.depth(phy) 103 | XY <- if(use.edge.length){ 104 | .unrooted.xy(Ntip, Nnode, phy$edge, phy$edge.length, nb.sp) 105 | } else { 106 | .unrooted.xy(Ntip, Nnode, phy$edge, rep(1, Nedge), nb.sp) 107 | } 108 | xx <- XY$M[, 1] - min(XY$M[, 1]) 109 | yy <- XY$M[, 2] - min(XY$M[, 2]) 110 | layout <- cbind(x=xx,y=yy) 111 | if(is.null(phy$node.label)) phy <- ape::makeNodeLabel(phy) 112 | if(anyDuplicated(c(phy$tip.label, phy$node.label))) 113 | stop("Duplicated labels!") 114 | rownames(layout) <- c(phy$tip.label,phy$node.label) 115 | centralVertex <- phy$node.label[1] 116 | return(list(phylo=phy, layout=layout,centralVertex=centralVertex)) 117 | } 118 | 119 | #------------------------------------------------------------------------------- 120 | # This function gets coordinates from an unrooted 'phylo' objects, 121 | # derived from a currectly not exported function from the ape package 122 | .unrooted.xy <- function(Ntip, Nnode, edge, edge.length, nb.sp){ 123 | foo <- function(node, ANGLE, AXIS) { 124 | ind <- which(edge[, 1] == node) 125 | sons <- edge[ind, 2] 126 | start <- AXIS - ANGLE/2 127 | for (i in 1:length(sons)) { 128 | h <- edge.length[ind[i]] 129 | angle[sons[i]] <<- alpha <- ANGLE*nb.sp[sons[i]]/nb.sp[node] 130 | axis[sons[i]] <<- beta <- start + alpha/2 131 | start <- start + alpha 132 | xx[sons[i]] <<- h*cos(beta) + xx[node] 133 | yy[sons[i]] <<- h*sin(beta) + yy[node] 134 | } 135 | for (i in sons) 136 | if (i > Ntip) foo(i, angle[i], axis[i]) 137 | } 138 | Nedge <- dim(edge)[1] 139 | yy <- xx <- numeric(Ntip + Nnode) 140 | axis <- angle <- numeric(Ntip + Nnode) 141 | foo(Ntip + 1L, 2*pi, 0) 142 | M <- cbind(xx, yy) 143 | axe <- axis[1:Ntip] 144 | axeGTpi <- axe > pi 145 | axe[axeGTpi] <- axe[axeGTpi] - 2*pi 146 | list(M = M, axe = axe) 147 | } 148 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TreeAndLeaf 2 | An R package for displaying binary trees, aiming to represent multiple layers of information on dendrogram leaves. 3 | 4 | ## Installation 5 | Install TreeAndLeaf from github: 6 | 7 | ```{r} 8 | if (! requireNamespace("devtools", quietly = TRUE)) 9 | install.packages("devtools") 10 | devtools::install_github("sysbiolab/TreeAndLeaf", force = TRUE, build_vignettes = TRUE) 11 | ``` 12 | 13 | For more info on how to use the package: 14 | 15 | ```{r} 16 | vignette("TreeAndLeaf") 17 | ``` 18 | -------------------------------------------------------------------------------- /build/vignette.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysbiolab/TreeAndLeaf/7ea90400b10199518cc22ec6ad1075acefdd1550/build/vignette.rds -------------------------------------------------------------------------------- /data/phylo_species.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysbiolab/TreeAndLeaf/7ea90400b10199518cc22ec6ad1075acefdd1550/data/phylo_species.RData -------------------------------------------------------------------------------- /data/phylo_tree.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysbiolab/TreeAndLeaf/7ea90400b10199518cc22ec6ad1075acefdd1550/data/phylo_tree.RData -------------------------------------------------------------------------------- /data/spdata.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysbiolab/TreeAndLeaf/7ea90400b10199518cc22ec6ad1075acefdd1550/data/spdata.RData -------------------------------------------------------------------------------- /inst/NEWS.Rd: -------------------------------------------------------------------------------- 1 | \name{TreeAndLeaf-News} 2 | \title{TreeAndLeaf News} 3 | \encoding{UTF-8} 4 | 5 | \section{Version 1.5.1} 6 | \itemize{ 7 | \item Object transformation functions condensed into the `treeAndLeaf` function, to be made automatically [2020-08-24]. 8 | \item TreeAndLeaf function became more automated. 9 | \item The igraph object manipulation was upgraded, through the use of RedeR functions. 10 | } 11 | } 12 | 13 | \section{Version 0.99.0}{ 14 | \itemize{ 15 | \item Submitted to Bioconductor [2019-12-16]. 16 | } 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /inst/doc/TreeAndLeaf.R: -------------------------------------------------------------------------------- 1 | ## ---- include = FALSE--------------------------------------------------------- 2 | knitr::opts_chunk$set( 3 | collapse = TRUE, 4 | comment = "#>" 5 | ) 6 | 7 | ## ---- eval=TRUE, message=FALSE------------------------------------------------ 8 | #-- Libraries required in this section: 9 | #-- TreeAndLeaf(>=1.4.2), RedeR(>=1.40.4), Bioconductor >= 3.13 (R >= 4.0) 10 | # BiocManager::install(c("TreeAndLeaf","RedeR")) 11 | # install.packages(c("igraph","RColorBrewer")) 12 | 13 | #-- Load packages 14 | library("TreeAndLeaf") 15 | library("RedeR") 16 | library("igraph") 17 | library("RColorBrewer") 18 | 19 | ## ---- eval=TRUE, message=FALSE------------------------------------------------ 20 | #-- Check data 21 | dim(USArrests) 22 | head(USArrests) 23 | 24 | ## ---- eval=TRUE, message=FALSE------------------------------------------------ 25 | hc <- hclust(dist(USArrests), "ave") 26 | plot(hc, main="Dendrogram for the 'USArrests' dataset", 27 | xlab="", sub="") 28 | 29 | ## ---- eval=FALSE-------------------------------------------------------------- 30 | # #-- Convert the 'hclust' object into a 'tree-and-leaf' object 31 | # tal <- treeAndLeaf(hc) 32 | 33 | ## ---- eval=FALSE-------------------------------------------------------------- 34 | # #--- Map attributes to the tree-and-leaf 35 | # #Note: 'refcol = 0' indicates that 'dat' rownames will be used as mapping IDs 36 | # tal <- att.mapv(g = tal, dat = USArrests, refcol = 0) 37 | 38 | ## ---- eval=FALSE-------------------------------------------------------------- 39 | # #--- Set graph attributes using the 'att.setv' wrapper function 40 | # pal <- brewer.pal(9, "Reds") 41 | # tal <- att.setv(g = tal, from = "Murder", to = "nodeColor", 42 | # cols = pal, nquant = 5) 43 | # tal <- att.setv(g = tal, from = "UrbanPop", to = "nodeSize", 44 | # xlim = c(10, 50, 5), nquant = 5) 45 | # 46 | # #--- Set graph attributes using 'att.addv' and 'att.adde' functions 47 | # tal <- att.addv(tal, "nodeFontSize", value = 15, index = V(tal)$isLeaf) 48 | # tal <- att.adde(tal, "edgeWidth", value = 3) 49 | 50 | ## ---- eval=FALSE-------------------------------------------------------------- 51 | # #--- Call RedeR application 52 | # rdp <- RedPort() 53 | # calld(rdp) 54 | # resetd(rdp) 55 | 56 | ## ---- eval=FALSE-------------------------------------------------------------- 57 | # #--- Send the tree-and-leaf to the interactive R/Java interface 58 | # addGraph(obj = rdp, g = tal, gzoom=75) 59 | # 60 | # #--- Call 'relax' to fine-tune the leaf nodes 61 | # relax(rdp, p1=25, p2=200, p3=5, p5=5, ps=TRUE) 62 | 63 | ## ---- eval=FALSE-------------------------------------------------------------- 64 | # #--- Add legends 65 | # addLegend.color(obj = rdp, tal, title = "Murder Rate", 66 | # position = "topright") 67 | # addLegend.size(obj = rdp, tal, title = "Urban Population Size", 68 | # position = "bottomright") 69 | 70 | ## ---- eval=FALSE, message=FALSE----------------------------------------------- 71 | # #-- Libraries required in this section: 72 | # #-- TreeAndLeaf(>=1.4.2), RedeR(>=1.40.4), Bioconductor >= 3.13 (R >= 4.0) 73 | # # BiocManager::install(c("TreeAndLeaf","RedeR","ggtree)) 74 | # # install.packages(c("igraph","ape", "dendextend", "dplyr", 75 | # # "ggplot2", "RColorBrewer")) 76 | # 77 | # #-- Load packages 78 | # library("TreeAndLeaf") 79 | # library("RedeR") 80 | # library("igraph") 81 | # library("ape") 82 | # library("ggtree") 83 | # library("dendextend") 84 | # library("dplyr") 85 | # library("ggplot2") 86 | # library("RColorBrewer") 87 | 88 | ## ---- eval=FALSE-------------------------------------------------------------- 89 | # #--- Generate a random phylo tree 90 | # phylo_tree <- rcoal(300) 91 | # 92 | # #--- Set groups and node sizes 93 | # group <- size <- dendextend::cutree(phylo_tree, 10) 94 | # group[] <- LETTERS[1:10][group] 95 | # size[] <- sample(size) 96 | # group.df <- data.frame(label=names(group), group=group, size=size) 97 | # phylo_tree <- dplyr::full_join(phylo_tree, group.df, by='label') 98 | # 99 | # #--- Generate a ggtree with 'daylight' layout 100 | # pal <- brewer.pal(10, "Set3") 101 | # ggt <- ggtree(phylo_tree, layout = 'daylight', branch.length='none') 102 | # 103 | # #--- Plot the ggtree 104 | # ggt + geom_tippoint(aes(color=group, size=size)) + 105 | # scale_color_manual(values=pal) + scale_y_reverse() 106 | 107 | ## ---- eval=FALSE-------------------------------------------------------------- 108 | # #-- Convert the 'ggtree' object into a 'tree-and-leaf' object 109 | # tal <- treeAndLeaf(ggt) 110 | # 111 | # #--- Map attributes to the tree-and-leaf 112 | # #Note: 'refcol = 1' indicates that 'dat' col 1 will be used as mapping IDs 113 | # tal <- att.mapv(g = tal, dat = group.df, refcol = 1) 114 | # 115 | # #--- Set graph attributes using the 'att.setv' wrapper function 116 | # tal <- att.setv(g = tal, from = "group", to = "nodeColor", 117 | # cols = pal) 118 | # tal <- att.setv(g = tal, from = "size", to = "nodeSize", 119 | # xlim = c(10, 50, 5)) 120 | # 121 | # #--- Set graph attributes using 'att.addv' and 'att.adde' functions 122 | # tal <- att.addv(tal, "nodeFontSize", value = 1) 123 | # tal <- att.addv(tal, "nodeLineWidth", value = 0) 124 | # tal <- att.addv(tal, "nodeColor", value = "black", index=!V(tal)$isLeaf) 125 | # tal <- att.adde(tal, "edgeWidth", value = 3) 126 | # tal <- att.adde(tal, "edgeColor", value = "black") 127 | 128 | ## ---- eval=FALSE-------------------------------------------------------------- 129 | # #--- Call RedeR application 130 | # rdp <- RedPort() 131 | # calld(rdp) 132 | # resetd(rdp) 133 | 134 | ## ---- eval=FALSE-------------------------------------------------------------- 135 | # #--- Send the tree-and-leaf to the interactive R/Java interface 136 | # addGraph(obj = rdp, g = tal, gzoom=50) 137 | # 138 | # #--- Select inner nodes, preventing them from relaxing 139 | # selectNodes(rdp, V(tal)$name[!V(tal)$isLeaf], anchor=TRUE) 140 | # 141 | # #--- Call 'relax' to fine-tune the leaf nodes 142 | # relax(rdp, p1=25, p2=100, p3=5, p5=1, p8=5, ps=TRUE) 143 | # 144 | # #--- Add legends 145 | # addLegend.color(obj = rdp, tal, title = "Group", 146 | # position = "topright",vertical=T) 147 | # addLegend.size(obj = rdp, tal, title = "Size", 148 | # position = "topleft", 149 | # vertical=T, dxtitle=10) 150 | 151 | ## ---- eval=FALSE, message=FALSE----------------------------------------------- 152 | # #-- Libraries required in this section: 153 | # #-- TreeAndLeaf(>=1.4.2), RedeR(>=1.40.4), Bioconductor >= 3.13 (R >= 4.0) 154 | # # BiocManager::install(c("TreeAndLeaf","RedeR")) 155 | # # install.packages(c("igraph", "RColorBrewer")) 156 | # 157 | # #-- Load packages 158 | # library(TreeAndLeaf) 159 | # library(RedeR) 160 | # library(igraph) 161 | # library(RColorBrewer) 162 | 163 | ## ----echo=TRUE---------------------------------------------------------------- 164 | #-- Check data 165 | dim(quakes) 166 | head(quakes) 167 | 168 | ## ---- eval=TRUE, message=FALSE------------------------------------------------ 169 | #-- Building a large dendrogram 170 | hc <- hclust(dist(quakes), "ave") 171 | plot(hc, main="Dendrogram for the 'quakes' dataset", 172 | xlab="", sub="") 173 | 174 | ## ---- eval=FALSE-------------------------------------------------------------- 175 | # #-- Convert the 'hclust' object into a 'tree-and-leaf' object 176 | # tal <- treeAndLeaf(hc) 177 | 178 | ## ---- eval=FALSE-------------------------------------------------------------- 179 | # #--- Map attributes to the tree-and-leaf 180 | # #Note: 'refcol = 0' indicates that 'dat' rownames will be used as mapping IDs 181 | # tal <- att.mapv(tal, quakes, refcol = 0) 182 | # 183 | # #--- Set graph attributes using the 'att.setv' wrapper function 184 | # pal <- brewer.pal(9, "Greens") 185 | # tal <- att.setv(g = tal, from = "mag", to = "nodeColor", 186 | # cols = pal, nquant = 10) 187 | # tal <- att.setv(g = tal, from = "depth", to = "nodeSize", 188 | # xlim = c(40, 120, 20), nquant = 5) 189 | # 190 | # #--- Set graph attributes using 'att.addv' and 'att.adde' functions 191 | # tal <- att.addv(tal, "nodeFontSize", value = 1) 192 | # tal <- att.adde(tal, "edgeWidth", value = 10) 193 | 194 | ## ---- eval=FALSE-------------------------------------------------------------- 195 | # #--- Call RedeR application 196 | # rdp <- RedPort() 197 | # calld(rdp) 198 | # resetd(rdp) 199 | 200 | ## ---- eval=FALSE-------------------------------------------------------------- 201 | # #--- Send the tree-and-leaf to the interactive R/Java interface 202 | # addGraph(obj = rdp, g = tal, gzoom=10) 203 | # 204 | # #--- Call 'relax' to fine-tune the leaf nodes 205 | # relax(rdp, p1=25, p2=200, p3=10, p4=100, p5=10, ps=TRUE) 206 | 207 | ## ---- eval=FALSE-------------------------------------------------------------- 208 | # #--- Add legends 209 | # addLegend.color(obj = rdp, tal, title = "Richter Magnitude", 210 | # position = "bottomright") 211 | # addLegend.size(obj = rdp, tal, title = "Depth (km)") 212 | 213 | ## ---- eval=TRUE, message=FALSE------------------------------------------------ 214 | #-- Libraries required in this section: 215 | #-- TreeAndLeaf(>=1.4.2), RedeR(>=1.40.4), Bioconductor >= 3.13 (R >= 4.0) 216 | # BiocManager::install(c("TreeAndLeaf","RedeR","geneplast)) 217 | # install.packages(c("igraph","ape", "RColorBrewer")) 218 | 219 | #-- Load packages 220 | library(TreeAndLeaf) 221 | library(RedeR) 222 | library(igraph) 223 | library(ape) 224 | library(geneplast) 225 | library(RColorBrewer) 226 | 227 | ## ---- eval=TRUE, message=FALSE------------------------------------------------ 228 | #-- Load data and plot the phylogenetic tree 229 | data("spdata") 230 | data("gpdata.gs") 231 | plot(phyloTree) 232 | 233 | ## ---- eval=FALSE-------------------------------------------------------------- 234 | # #--- Drop organisms not listed in the 'spdata' annotation 235 | # phyloTree$tip.label <- as.character(phyloTree$tip.label) 236 | # tokeep <- phyloTree$tip.label %in% spdata$tax_id 237 | # pruned.phylo <- drop.tip(phyloTree, phyloTree$tip.label[!tokeep]) 238 | 239 | ## ---- eval=FALSE-------------------------------------------------------------- 240 | # #-- Convert the phylogenetic tree into a 'tree-and-leaf' object 241 | # tal <- treeAndLeaf(pruned.phylo) 242 | # 243 | # #--- Map attributes to the tree-and-leaf 244 | # #Note: 'refcol = 1' indicates that 'dat' col 1 will be used as mapping IDs 245 | # tal <- att.mapv(g = tal, dat = spdata, refcol = 1) 246 | # 247 | # #--- Set graph attributes using the 'att.setv' wrapper function 248 | # pal <- brewer.pal(9, "Purples") 249 | # tal <- att.setv(g = tal, from = "genome_size_Mb", 250 | # to = "nodeSize", xlim = c(120, 250, 1), nquant = 5) 251 | # tal <- att.setv (g = tal, from = "proteins", 252 | # to = "nodeColor", nquant = 5, 253 | # cols = pal, na.col = "black") 254 | 255 | ## ---- eval=FALSE-------------------------------------------------------------- 256 | # #--- Add graph attributes using 'att.adde' and 'att.addv' functions 257 | # tal <- att.addv(tal, "nodeFontSize", value = 10) 258 | # tal <- att.adde(tal, "edgeWidth", value = 20) 259 | # 260 | # # Set species names to 'nodeAlias' attribute 261 | # tal <- att.setv(tal, from = "sp_name", to = "nodeAlias") 262 | # 263 | # # Select a few names to highlight in the graph 264 | # tal <- att.addv(tal, "nodeFontSize", value = 100, 265 | # filter=list('name'=sample(pruned.phylo$tip.label,30))) 266 | # tal <- att.addv(tal, "nodeFontSize", value = 100, 267 | # filter=list('name'="9606")) #Homo sapiens 268 | 269 | ## ---- eval=FALSE-------------------------------------------------------------- 270 | # # Call RedeR 271 | # rdp <- RedPort() 272 | # calld(rdp) 273 | # resetd(rdp) 274 | # 275 | # #--- Send the tree-and-leaf to the interactive R/Java interface 276 | # addGraph(obj = rdp, g = tal, gzoom=10) 277 | # 278 | # #--- Call 'relax' to fine-tune the leaf nodes 279 | # relax(rdp, ps=TRUE) 280 | 281 | ## ---- eval=FALSE-------------------------------------------------------------- 282 | # #--- Add legends 283 | # addLegend.color(rdp, tal, title = "Proteome Size (n)") 284 | # addLegend.size(rdp, tal, title = "Genome Size (Mb)") 285 | 286 | ## ---- eval=FALSE-------------------------------------------------------------- 287 | # #-- Libraries required in this section: 288 | # #-- TreeAndLeaf(>=1.4.2), RedeR(>=1.40.4), Bioconductor >= 3.13 (R >= 4.0) 289 | # # BiocManager::install(c("TreeAndLeaf","RedeR","geneplast)) 290 | # # install.packages(c("igraph","ape", "RColorBrewer")) 291 | # 292 | # #-- Load packages 293 | # library(TreeAndLeaf) 294 | # library(RedeR) 295 | # library(igraph) 296 | # library(ape) 297 | # library(geneplast) 298 | # library(RColorBrewer) 299 | 300 | ## ---- eval=FALSE, message=FALSE----------------------------------------------- 301 | # #-- Load data 302 | # data("spdata") 303 | # data("phylo_tree") 304 | 305 | ## ---- eval=FALSE, message=FALSE----------------------------------------------- 306 | # #--- Drop organisms not listed in the 'spdata' annotation 307 | # tokeep <- phylo_tree$tip.label %in% spdata$tax_id 308 | # pruned.phylo <- drop.tip(phylo_tree, phylo_tree$tip.label[!tokeep]) 309 | 310 | ## ---- eval=FALSE-------------------------------------------------------------- 311 | # #-- Convert the phylogenetic tree into a 'tree-and-leaf' object 312 | # tal <- treeAndLeaf(pruned.phylo) 313 | 314 | ## ---- eval=FALSE-------------------------------------------------------------- 315 | # #--- Map attributes to the tree-and-leaf using "%>%" operator 316 | # tal <- tal %>% 317 | # att.mapv(dat = spdata, refcol = 1) %>% 318 | # att.setv(from = "genome_size_Mb", to = "nodeSize", 319 | # xlim = c(120, 250, 1), nquant = 5) %>% 320 | # att.setv(from = "proteins", to = "nodeColor", nquant = 5, 321 | # cols = brewer.pal(9, "Blues"), na.col = "black") %>% 322 | # att.setv(from = "sp_name", to = "nodeAlias") %>% 323 | # att.adde(to = "edgeWidth", value = 20) %>% 324 | # att.addv(to = "nodeFontSize", value = 10) %>% 325 | # att.addv(to = "nodeFontSize", value = 100, 326 | # filter = list("name" = sample(pruned.phylo$tip.label, 30))) %>% 327 | # att.addv(to = "nodeFontSize", value = 100, 328 | # filter = list("name" = "9606")) 329 | 330 | ## ---- eval=FALSE-------------------------------------------------------------- 331 | # # Call RedeR 332 | # rdp <- RedPort() 333 | # calld(rdp) 334 | # resetd(rdp) 335 | # 336 | # #--- Send the tree-and-leaf to the interactive R/Java interface 337 | # addGraph(obj = rdp, g = tal, gzoom=5) 338 | # 339 | # #--- Call 'relax' to fine-tune the leaf nodes 340 | # relax(rdp, ps=TRUE) 341 | 342 | ## ---- eval=FALSE-------------------------------------------------------------- 343 | # #--- Add legends 344 | # addLegend.color(rdp, tal, title = "Proteome Size (n)") 345 | # addLegend.size(rdp, tal, title = "Genome size (Mb)") 346 | 347 | ## ----label='Session information', eval=TRUE, echo=FALSE----------------------- 348 | sessionInfo() 349 | 350 | -------------------------------------------------------------------------------- /inst/doc/TreeAndLeaf.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: '*TreeAndLeaf*: A graph layout strategy for binary trees with focus on the leaves' 3 | author: 'Milena A Cardoso, Luis E A Rizzardi, Leonardo W Kume, Sheyla Trefflich, Clarice Groeneveld, Mauro A A Castro' 4 | date: "`r BiocStyle::doc_date()`" 5 | abstract: "The **TreeAndLeaf** package combines tree and force-directed layout algorithms for drawing binary trees, aiming to represent multiple layers of information onto the leaves." 6 | package: "`r BiocStyle::pkg_ver('TreeAndLeaf')`" 7 | output: 8 | BiocStyle::html_document: 9 | css: custom.css 10 | vignette: > 11 | %\VignetteIndexEntry{TreeAndLeaf: an graph layout to dendrograms.} 12 | %\VignetteEngine{knitr::rmarkdown} 13 | %\VignetteEncoding{UTF-8} 14 | --- 15 | 16 | ```{r, include = FALSE} 17 | knitr::opts_chunk$set( 18 | collapse = TRUE, 19 | comment = "#>" 20 | ) 21 | ``` 22 | 23 | # Overview 24 | 25 | A dendrogram diagram displays binary trees focused on representing 26 | hierarchical relations between the tree elements. A dendrogram contains 27 | nodes, branches (edges), a root, and leaves (**Figure 1A**). The root is where 28 | the branches and nodes come from, indicating the direction to the leaves, 29 | *i.e.*, the terminal nodes. 30 | 31 | Most of the space of a dendrogram layout is used to arrange branches and inner 32 | nodes, with limited space to the leaves. For large dendrograms, the leaf 33 | labels are often squeezed to fit into small slots. Therefore, a dendrogram 34 | may not provide the best layout when the information to be displayed should 35 | highlight the leaves. 36 | 37 | The **TreeAndLeaf** package aims to improve the visualization of the dendrogram 38 | leaves by combining tree and force-directed layout algorithms, shifting the 39 | focus of analysis to the leaves (**Figure 1B**). The package's workflow is 40 | summarized in **Figure 1C**. 41 | 42 |

43 | 44 |

45 | **Figure 1**. **TreeAndLeaf** workflow summary. **(A,B)** The dendrogram in A 46 | is used to construct the graph in B. **(C)** The main input for the **TreeAndLeaf** 47 | package consists of a dendrogram, and then the package transforms the dendrogram 48 | into a graph representation. The finest graph layout is achieved by a two-steps 49 | process, starting with an unrooted tree diagram, which is subsequently relaxed 50 | by a force-directed algorithm applied to the terminal nodes of the tree. The 51 | final *tree-and-leaf* layout varies depending on the initial state, which can be 52 | obtained by other tree layout algorithms (see *section 3* for examples using 53 | *ggtree* layouts to setup the initial state). 54 | 55 | # Quick Start 56 | 57 | This section provides a basic example using the R built-in `USArrests` dataset. 58 | The `USArrests` is a dataframe available in the user's workspace. To know more 59 | about this dataframe, please query `?USArrests` in the R console. We will build 60 | a dendrogram from the `USArrests` dataset, then transform the dendrogram into 61 | a *tree-and-leaf* diagram, and the result will be visualized in the **RedeR** 62 | application. 63 | 64 | ## Package and data requirements 65 | 66 | ```{r, eval=TRUE, message=FALSE} 67 | #-- Libraries required in this section: 68 | #-- TreeAndLeaf(>=1.4.2), RedeR(>=1.40.4), Bioconductor >= 3.13 (R >= 4.0) 69 | # BiocManager::install(c("TreeAndLeaf","RedeR")) 70 | # install.packages(c("igraph","RColorBrewer")) 71 | 72 | #-- Load packages 73 | library("TreeAndLeaf") 74 | library("RedeR") 75 | library("igraph") 76 | library("RColorBrewer") 77 | ``` 78 | 79 | ```{r, eval=TRUE, message=FALSE} 80 | #-- Check data 81 | dim(USArrests) 82 | head(USArrests) 83 | ``` 84 | 85 | ## Building a dendrogram example 86 | 87 | In order to build a dendrogram from the `USArrests` dataset, we need a distance 88 | matrix. We will use the default "euclidean distance" method from the `dist()` 89 | function, and then the "average" method from `hclust()` function to create the 90 | dendrogram. 91 | 92 | ```{r, eval=TRUE, message=FALSE} 93 | hc <- hclust(dist(USArrests), "ave") 94 | plot(hc, main="Dendrogram for the 'USArrests' dataset", 95 | xlab="", sub="") 96 | ``` 97 | 98 | ## Converting the *hclust* object into a *tree-and-leaf* object 99 | 100 | The `treeAndLeaf` function will transform the *hclust* into an *igraph* object, 101 | including some basic graph attributes to display in the **RedeR** application. 102 | 103 | ```{r, eval=FALSE} 104 | #-- Convert the 'hclust' object into a 'tree-and-leaf' object 105 | tal <- treeAndLeaf(hc) 106 | ``` 107 | 108 | ## Setting graph attributes 109 | 110 | The `att.mapv()` function can be used to add external annotations to an *igraph* 111 | object, for example, mapping new variables to the graph vertices. We will add 112 | all `USArrests` variables to the `tal` object. To map one object to another 113 | it is essential to use the same mapping IDs, set by the `refcol` parameter, 114 | which points to a column in the input annotation dataset. In this example, 115 | `refcol = 0` indicates that the `USArrests` rownames will be used as 116 | mapping IDs. To check the IDs in the *igraph* vertices, please type 117 | `V(tal)$name` in the R console. 118 | 119 | ```{r, eval=FALSE} 120 | #--- Map attributes to the tree-and-leaf 121 | #Note: 'refcol = 0' indicates that 'dat' rownames will be used as mapping IDs 122 | tal <- att.mapv(g = tal, dat = USArrests, refcol = 0) 123 | ``` 124 | 125 | Now we use the `att.setv()` wrapper function to set attributes in the 126 | *tree-and-leaf* diagram. To see all attributes available to display in the 127 | **RedeR** application, please type `?addGraph` in the R console. The graph 128 | attributes can also be customized following **igraph** syntax rules. 129 | 130 | ```{r, eval=FALSE} 131 | #--- Set graph attributes using the 'att.setv' wrapper function 132 | pal <- brewer.pal(9, "Reds") 133 | tal <- att.setv(g = tal, from = "Murder", to = "nodeColor", 134 | cols = pal, nquant = 5) 135 | tal <- att.setv(g = tal, from = "UrbanPop", to = "nodeSize", 136 | xlim = c(10, 50, 5), nquant = 5) 137 | 138 | #--- Set graph attributes using 'att.addv' and 'att.adde' functions 139 | tal <- att.addv(tal, "nodeFontSize", value = 15, index = V(tal)$isLeaf) 140 | tal <- att.adde(tal, "edgeWidth", value = 3) 141 | ``` 142 | 143 | ## Plotting a *tree-and-leaf* diagram 144 | 145 | The next steps will call the **RedeR** application, and then display the 146 | *tree-and-leaf* diagram in an interactive R/Java interface. The initial layout 147 | will show an unrooted tree diagram, which will be subsequently relaxed by a 148 | force-directed algorithm applied to the terminal nodes of the tree. 149 | 150 | ```{r, eval=FALSE} 151 | #--- Call RedeR application 152 | rdp <- RedPort() 153 | calld(rdp) 154 | resetd(rdp) 155 | ``` 156 | 157 | ```{r, eval=FALSE} 158 | #--- Send the tree-and-leaf to the interactive R/Java interface 159 | addGraph(obj = rdp, g = tal, gzoom=75) 160 | 161 | #--- Call 'relax' to fine-tune the leaf nodes 162 | relax(rdp, p1=25, p2=200, p3=5, p5=5, ps=TRUE) 163 | ``` 164 | 165 | At this point, the user can interact with the layout process to achieve the 166 | best or desired layout; we suggest fine-tuning the force-directed algorithm 167 | parameters, either through the R/Java interface or the command line relaxation 168 | function. Note that the unroot tree diagram represents the initial state; then 169 | a relaxing process should start until the finest graph layout is achieved. 170 | The final layout varies depending on the initial state, which can also be 171 | adjusted by providing more or less room for the spatial configuration 172 | (*e.g.* via `gzoom` parameter). 173 | 174 | ```{r, eval=FALSE} 175 | #--- Add legends 176 | addLegend.color(obj = rdp, tal, title = "Murder Rate", 177 | position = "topright") 178 | addLegend.size(obj = rdp, tal, title = "Urban Population Size", 179 | position = "bottomright") 180 | ``` 181 | 182 |

183 | 184 |

185 | 186 | # Setting the initial *tree-and-leaf* state with *ggtree* layouts 187 | 188 | The tree diagram represents the initial state of a *tree-and-leaf*, which is then 189 | relaxed by a force-directed algorithm applied to the terminal nodes. Therefore, 190 | the final *tree-and-leaf* layout varies depending on the initial state. The 191 | **treeAndLeaf** package also accepts `ggtree` layouts to setup the initial state. 192 | For example, next we show a tree diagram generated by the **ggtree** package, 193 | and then we apply the *tree-and-leaf* transformation. 194 | 195 | ## Package and data requirements 196 | 197 | ```{r, eval=FALSE, message=FALSE} 198 | #-- Libraries required in this section: 199 | #-- TreeAndLeaf(>=1.4.2), RedeR(>=1.40.4), Bioconductor >= 3.13 (R >= 4.0) 200 | # BiocManager::install(c("TreeAndLeaf","RedeR","ggtree)) 201 | # install.packages(c("igraph","ape", "dendextend", "dplyr", 202 | # "ggplot2", "RColorBrewer")) 203 | 204 | #-- Load packages 205 | library("TreeAndLeaf") 206 | library("RedeR") 207 | library("igraph") 208 | library("ape") 209 | library("ggtree") 210 | library("dendextend") 211 | library("dplyr") 212 | library("ggplot2") 213 | library("RColorBrewer") 214 | ``` 215 | 216 | ## Building and plotting a *phylo* tree with *ggtree* layouts 217 | 218 | ```{r, eval=FALSE} 219 | #--- Generate a random phylo tree 220 | phylo_tree <- rcoal(300) 221 | 222 | #--- Set groups and node sizes 223 | group <- size <- dendextend::cutree(phylo_tree, 10) 224 | group[] <- LETTERS[1:10][group] 225 | size[] <- sample(size) 226 | group.df <- data.frame(label=names(group), group=group, size=size) 227 | phylo_tree <- dplyr::full_join(phylo_tree, group.df, by='label') 228 | 229 | #--- Generate a ggtree with 'daylight' layout 230 | pal <- brewer.pal(10, "Set3") 231 | ggt <- ggtree(phylo_tree, layout = 'daylight', branch.length='none') 232 | 233 | #--- Plot the ggtree 234 | ggt + geom_tippoint(aes(color=group, size=size)) + 235 | scale_color_manual(values=pal) + scale_y_reverse() 236 | ``` 237 | 238 | ## Applying *tree-and-leaf* transformation to *ggtree* layouts 239 | 240 | ```{r, eval=FALSE} 241 | #-- Convert the 'ggtree' object into a 'tree-and-leaf' object 242 | tal <- treeAndLeaf(ggt) 243 | 244 | #--- Map attributes to the tree-and-leaf 245 | #Note: 'refcol = 1' indicates that 'dat' col 1 will be used as mapping IDs 246 | tal <- att.mapv(g = tal, dat = group.df, refcol = 1) 247 | 248 | #--- Set graph attributes using the 'att.setv' wrapper function 249 | tal <- att.setv(g = tal, from = "group", to = "nodeColor", 250 | cols = pal) 251 | tal <- att.setv(g = tal, from = "size", to = "nodeSize", 252 | xlim = c(10, 50, 5)) 253 | 254 | #--- Set graph attributes using 'att.addv' and 'att.adde' functions 255 | tal <- att.addv(tal, "nodeFontSize", value = 1) 256 | tal <- att.addv(tal, "nodeLineWidth", value = 0) 257 | tal <- att.addv(tal, "nodeColor", value = "black", index=!V(tal)$isLeaf) 258 | tal <- att.adde(tal, "edgeWidth", value = 3) 259 | tal <- att.adde(tal, "edgeColor", value = "black") 260 | ``` 261 | 262 | ```{r, eval=FALSE} 263 | #--- Call RedeR application 264 | rdp <- RedPort() 265 | calld(rdp) 266 | resetd(rdp) 267 | ``` 268 | 269 | ```{r, eval=FALSE} 270 | #--- Send the tree-and-leaf to the interactive R/Java interface 271 | addGraph(obj = rdp, g = tal, gzoom=50) 272 | 273 | #--- Select inner nodes, preventing them from relaxing 274 | selectNodes(rdp, V(tal)$name[!V(tal)$isLeaf], anchor=TRUE) 275 | 276 | #--- Call 'relax' to fine-tune the leaf nodes 277 | relax(rdp, p1=25, p2=100, p3=5, p5=1, p8=5, ps=TRUE) 278 | 279 | #--- Add legends 280 | addLegend.color(obj = rdp, tal, title = "Group", 281 | position = "topright",vertical=T) 282 | addLegend.size(obj = rdp, tal, title = "Size", 283 | position = "topleft", 284 | vertical=T, dxtitle=10) 285 | ``` 286 | 287 |

288 | 289 |

290 | 291 | # Case Study 1: visualizing a large dendrogram 292 | 293 | ## Context 294 | 295 | This section follows the same steps described in the *Quick Start*, but 296 | using a larger dendrogram derived from the R built-in `quakes` dataset. 297 | The `quakes` is a dataframe available in the user's workspace. To know more 298 | about this dataframe, please query `?quakes` in the R console. 299 | We will build a dendrogram from the `quakes` dataset, then transform the 300 | dendrogram into a *tree-and-leaf* diagram, and the result will be visualized 301 | in the **RedeR** application. 302 | 303 | ## Package and data requirements 304 | 305 | ```{r, eval=FALSE, message=FALSE} 306 | #-- Libraries required in this section: 307 | #-- TreeAndLeaf(>=1.4.2), RedeR(>=1.40.4), Bioconductor >= 3.13 (R >= 4.0) 308 | # BiocManager::install(c("TreeAndLeaf","RedeR")) 309 | # install.packages(c("igraph", "RColorBrewer")) 310 | 311 | #-- Load packages 312 | library(TreeAndLeaf) 313 | library(RedeR) 314 | library(igraph) 315 | library(RColorBrewer) 316 | ``` 317 | 318 | ```{r echo=TRUE} 319 | #-- Check data 320 | dim(quakes) 321 | head(quakes) 322 | ``` 323 | 324 | ```{r, eval=TRUE, message=FALSE} 325 | #-- Building a large dendrogram 326 | hc <- hclust(dist(quakes), "ave") 327 | plot(hc, main="Dendrogram for the 'quakes' dataset", 328 | xlab="", sub="") 329 | ``` 330 | 331 | ## Building and plotting a large *tree-and-leaf* diagram 332 | 333 | ```{r, eval=FALSE} 334 | #-- Convert the 'hclust' object into a 'tree-and-leaf' object 335 | tal <- treeAndLeaf(hc) 336 | ``` 337 | 338 | ```{r, eval=FALSE} 339 | #--- Map attributes to the tree-and-leaf 340 | #Note: 'refcol = 0' indicates that 'dat' rownames will be used as mapping IDs 341 | tal <- att.mapv(tal, quakes, refcol = 0) 342 | 343 | #--- Set graph attributes using the 'att.setv' wrapper function 344 | pal <- brewer.pal(9, "Greens") 345 | tal <- att.setv(g = tal, from = "mag", to = "nodeColor", 346 | cols = pal, nquant = 10) 347 | tal <- att.setv(g = tal, from = "depth", to = "nodeSize", 348 | xlim = c(40, 120, 20), nquant = 5) 349 | 350 | #--- Set graph attributes using 'att.addv' and 'att.adde' functions 351 | tal <- att.addv(tal, "nodeFontSize", value = 1) 352 | tal <- att.adde(tal, "edgeWidth", value = 10) 353 | ``` 354 | 355 | The next steps will call the **RedeR** application, and then display the 356 | *tree-and-leaf* diagram in an interactive R/Java interface. The initial layout 357 | will show an unrooted tree diagram, which will be subsequently relaxed by a 358 | force-directed algorithm applied to the terminal nodes of the tree. 359 | 360 | ```{r, eval=FALSE} 361 | #--- Call RedeR application 362 | rdp <- RedPort() 363 | calld(rdp) 364 | resetd(rdp) 365 | ``` 366 | 367 | ```{r, eval=FALSE} 368 | #--- Send the tree-and-leaf to the interactive R/Java interface 369 | addGraph(obj = rdp, g = tal, gzoom=10) 370 | 371 | #--- Call 'relax' to fine-tune the leaf nodes 372 | relax(rdp, p1=25, p2=200, p3=10, p4=100, p5=10, ps=TRUE) 373 | ``` 374 | 375 | ```{r, eval=FALSE} 376 | #--- Add legends 377 | addLegend.color(obj = rdp, tal, title = "Richter Magnitude", 378 | position = "bottomright") 379 | addLegend.size(obj = rdp, tal, title = "Depth (km)") 380 | ``` 381 | 382 |

383 | 384 |

385 | 386 | # Case Study 2: visualizing a phylogenetic tree 387 | 388 | ## Context 389 | 390 | This section generates a *tree-and-leaf* diagram from a pre-computed `phylo` 391 | tree object. We will use a phylogenetic tree listing 121 eukaryotes, available 392 | from the **geneplast** package. 393 | 394 | ## Package and data requirements 395 | 396 | ```{r, eval=TRUE, message=FALSE} 397 | #-- Libraries required in this section: 398 | #-- TreeAndLeaf(>=1.4.2), RedeR(>=1.40.4), Bioconductor >= 3.13 (R >= 4.0) 399 | # BiocManager::install(c("TreeAndLeaf","RedeR","geneplast)) 400 | # install.packages(c("igraph","ape", "RColorBrewer")) 401 | 402 | #-- Load packages 403 | library(TreeAndLeaf) 404 | library(RedeR) 405 | library(igraph) 406 | library(ape) 407 | library(geneplast) 408 | library(RColorBrewer) 409 | ``` 410 | 411 | ```{r, eval=TRUE, message=FALSE} 412 | #-- Load data and plot the phylogenetic tree 413 | data("spdata") 414 | data("gpdata.gs") 415 | plot(phyloTree) 416 | ``` 417 | 418 | ## Building and plotting a *tree-and-leaf* from a phylogenetic tree 419 | 420 | ```{r, eval=FALSE} 421 | #--- Drop organisms not listed in the 'spdata' annotation 422 | phyloTree$tip.label <- as.character(phyloTree$tip.label) 423 | tokeep <- phyloTree$tip.label %in% spdata$tax_id 424 | pruned.phylo <- drop.tip(phyloTree, phyloTree$tip.label[!tokeep]) 425 | ``` 426 | 427 | ```{r, eval=FALSE} 428 | #-- Convert the phylogenetic tree into a 'tree-and-leaf' object 429 | tal <- treeAndLeaf(pruned.phylo) 430 | 431 | #--- Map attributes to the tree-and-leaf 432 | #Note: 'refcol = 1' indicates that 'dat' col 1 will be used as mapping IDs 433 | tal <- att.mapv(g = tal, dat = spdata, refcol = 1) 434 | 435 | #--- Set graph attributes using the 'att.setv' wrapper function 436 | pal <- brewer.pal(9, "Purples") 437 | tal <- att.setv(g = tal, from = "genome_size_Mb", 438 | to = "nodeSize", xlim = c(120, 250, 1), nquant = 5) 439 | tal <- att.setv (g = tal, from = "proteins", 440 | to = "nodeColor", nquant = 5, 441 | cols = pal, na.col = "black") 442 | ``` 443 | 444 | ```{r, eval=FALSE} 445 | #--- Add graph attributes using 'att.adde' and 'att.addv' functions 446 | tal <- att.addv(tal, "nodeFontSize", value = 10) 447 | tal <- att.adde(tal, "edgeWidth", value = 20) 448 | 449 | # Set species names to 'nodeAlias' attribute 450 | tal <- att.setv(tal, from = "sp_name", to = "nodeAlias") 451 | 452 | # Select a few names to highlight in the graph 453 | tal <- att.addv(tal, "nodeFontSize", value = 100, 454 | filter=list('name'=sample(pruned.phylo$tip.label,30))) 455 | tal <- att.addv(tal, "nodeFontSize", value = 100, 456 | filter=list('name'="9606")) #Homo sapiens 457 | ``` 458 | 459 | ```{r, eval=FALSE} 460 | # Call RedeR 461 | rdp <- RedPort() 462 | calld(rdp) 463 | resetd(rdp) 464 | 465 | #--- Send the tree-and-leaf to the interactive R/Java interface 466 | addGraph(obj = rdp, g = tal, gzoom=10) 467 | 468 | #--- Call 'relax' to fine-tune the leaf nodes 469 | relax(rdp, ps=TRUE) 470 | ``` 471 | 472 | ```{r, eval=FALSE} 473 | #--- Add legends 474 | addLegend.color(rdp, tal, title = "Proteome Size (n)") 475 | addLegend.size(rdp, tal, title = "Genome Size (Mb)") 476 | ``` 477 | 478 |

479 | 480 |

481 | 482 | # Case Study 3: visualizing a non-binary tree 483 | 484 | ## Context 485 | 486 | The **TreeAndLeaf** package is designed to layout binary trees, but it can also 487 | layout other graph configurations. To exemplify this case, we will use a 488 | larger phylogenetic tree available from the **geneplast** package, and for 489 | which some inner nodes have more than two children, or non-binary nodes. 490 | 491 | ## Package and data requirements 492 | 493 | ```{r, eval=FALSE} 494 | #-- Libraries required in this section: 495 | #-- TreeAndLeaf(>=1.4.2), RedeR(>=1.40.4), Bioconductor >= 3.13 (R >= 4.0) 496 | # BiocManager::install(c("TreeAndLeaf","RedeR","geneplast)) 497 | # install.packages(c("igraph","ape", "RColorBrewer")) 498 | 499 | #-- Load packages 500 | library(TreeAndLeaf) 501 | library(RedeR) 502 | library(igraph) 503 | library(ape) 504 | library(geneplast) 505 | library(RColorBrewer) 506 | ``` 507 | 508 | ```{r, eval=FALSE, message=FALSE} 509 | #-- Load data 510 | data("spdata") 511 | data("phylo_tree") 512 | ``` 513 | 514 | ```{r, eval=FALSE, message=FALSE} 515 | #--- Drop organisms not listed in the 'spdata' annotation 516 | tokeep <- phylo_tree$tip.label %in% spdata$tax_id 517 | pruned.phylo <- drop.tip(phylo_tree, phylo_tree$tip.label[!tokeep]) 518 | ``` 519 | 520 | ## Building and plotting a *tree-and-leaf* for a non-binary tree 521 | 522 | ```{r, eval=FALSE} 523 | #-- Convert the phylogenetic tree into a 'tree-and-leaf' object 524 | tal <- treeAndLeaf(pruned.phylo) 525 | ``` 526 | 527 | ```{r, eval=FALSE} 528 | #--- Map attributes to the tree-and-leaf using "%>%" operator 529 | tal <- tal %>% 530 | att.mapv(dat = spdata, refcol = 1) %>% 531 | att.setv(from = "genome_size_Mb", to = "nodeSize", 532 | xlim = c(120, 250, 1), nquant = 5) %>% 533 | att.setv(from = "proteins", to = "nodeColor", nquant = 5, 534 | cols = brewer.pal(9, "Blues"), na.col = "black") %>% 535 | att.setv(from = "sp_name", to = "nodeAlias") %>% 536 | att.adde(to = "edgeWidth", value = 20) %>% 537 | att.addv(to = "nodeFontSize", value = 10) %>% 538 | att.addv(to = "nodeFontSize", value = 100, 539 | filter = list("name" = sample(pruned.phylo$tip.label, 30))) %>% 540 | att.addv(to = "nodeFontSize", value = 100, 541 | filter = list("name" = "9606")) 542 | ``` 543 | 544 | ```{r, eval=FALSE} 545 | # Call RedeR 546 | rdp <- RedPort() 547 | calld(rdp) 548 | resetd(rdp) 549 | 550 | #--- Send the tree-and-leaf to the interactive R/Java interface 551 | addGraph(obj = rdp, g = tal, gzoom=5) 552 | 553 | #--- Call 'relax' to fine-tune the leaf nodes 554 | relax(rdp, ps=TRUE) 555 | ``` 556 | 557 | ```{r, eval=FALSE} 558 | #--- Add legends 559 | addLegend.color(rdp, tal, title = "Proteome Size (n)") 560 | addLegend.size(rdp, tal, title = "Genome size (Mb)") 561 | ``` 562 | 563 |

564 | 565 |

566 | 567 | # Session information 568 | 569 | ```{r label='Session information', eval=TRUE, echo=FALSE} 570 | sessionInfo() 571 | ``` 572 | -------------------------------------------------------------------------------- /inst/unitTests/test_tal.R: -------------------------------------------------------------------------------- 1 | test_tal <- function(){ 2 | hc <- hclust(dist(USArrests), "average") 3 | tal <- treeAndLeaf(hc) 4 | RUnit::checkTrue(is(tal, "igraph")) 5 | RUnit::checkTrue(!is.null(tal$gtype)) 6 | RUnit::checkTrue(tal$gtype=="TreeAndLeaf") 7 | } 8 | test_theme<- function(){ 9 | hc <- hclust(dist(USArrests), "average") 10 | tal <- treeAndLeaf(hc) 11 | tal <- formatTree(tal, theme = 5) 12 | RUnit::checkTrue(is(tal, "igraph")) 13 | RUnit::checkTrue(!is.null(tal$gtype)) 14 | RUnit::checkTrue(tal$gtype=="TreeAndLeaf") 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /man/TreeAndLeaf-package.Rd: -------------------------------------------------------------------------------- 1 | \name{TreeAndLeaf-package} 2 | \alias{TreeAndLeaf-package} 3 | \alias{TreeAndLeaf} 4 | \docType{package} 5 | 6 | \title{ 7 | TreeAndLeaf: A graph layout for binary trees with focus on dendrogram leaves. 8 | } 9 | 10 | \description{ 11 | The TreeAndLeaf package combines unrooted and force-directed graph algorithms 12 | in order to layout binary trees, aiming to represent multiple layers of 13 | information onto dendrogram leaves. 14 | } 15 | 16 | \details{ 17 | \tabular{ll}{ 18 | Package: \tab TreeAndLeaf\cr 19 | Type: \tab Package\cr 20 | Depends: \tab R (>= 4.0)\cr 21 | Imports: \tab RedeR, igraph, ape \cr 22 | Suggests: \tab knitr, rmarkdown, BiocStyle, RUnit, BiocGenerics, stringr, 23 | RColorBrewer\cr 24 | License: \tab Artistic-2.0\cr 25 | biocViews: \tab NetworkEnrichment, GraphAndNetwork\cr 26 | } 27 | } 28 | 29 | \section{Index}{ 30 | 31 | \tabular{ll}{ 32 | \link{formatTree}: \tab A theme function for tree-and-leaf igraph objects.\cr 33 | \link{treeAndLeaf}: \tab Layout a TreeAndLeaf diagram.\cr 34 | } 35 | 36 | Further information is available from the vignettes 37 | \code{vignette("TreeAndLeaf")}. 38 | } 39 | 40 | \author{ 41 | Leonardo W. Kume, Luis E. A. Rizzardi, Milena A. Cardoso, Mauro A. A. Castro 42 | } 43 | 44 | \references{ 45 | CASTRO, M. A. et al. RedeR: R/Bioconductor package for representing modular 46 | structures, nested networks and multiple levels of hierarchical associations. 47 | \strong{Genome Biology}, 13(4):R29, 2012. 48 | 49 | CASTRO, M. A. A. et al. Regulators of genetic risk of breast cancer identified 50 | by integrative network analysis. \strong{Nature Genetics}, 48(1):12–21, 2016. 51 | 52 | RUSU, A.; SANTIAGO, C. Grid Drawings of Binary Trees: An Experimental 53 | Study. \strong{Journal of Graph Algorithms and Applications}, 54 | 12(2):131–195, 2008. 55 | } 56 | 57 | \keyword{package} 58 | 59 | -------------------------------------------------------------------------------- /man/formatTree.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/formatTree.R 3 | \name{formatTree} 4 | \alias{formatTree} 5 | \title{A theme function for tree-and-leaf igraph objects.} 6 | \usage{ 7 | formatTree(tal, theme = 1) 8 | } 9 | \arguments{ 10 | \item{tal}{An igraph object generated by the \code{\link{TreeAndLeaf}} function.} 11 | 12 | \item{theme}{An integer ranging from 1 to 5 with desired theme. \cr 13 | Options: \cr 14 | 1- A clean black and blue theme, for additional customizations. \cr 15 | 2- Green palette theme. \cr 16 | 3- Blue palette theme. \cr 17 | 4- Purple palette theme. \cr 18 | 5- Red palette theme. \cr 19 | For detailed customization, see attributes in the 20 | \code{\link[RedeR]{addGraph}} method. \cr} 21 | } 22 | \value{ 23 | An igraph object with attributes for RedeR application. 24 | } 25 | \description{ 26 | This function sets attributes of a tree-and-leaf igraph object for 27 | plotting in the RedeR app interface. 28 | } 29 | \examples{ 30 | library(RedeR) 31 | hc <- hclust(dist(USArrests), "ave") 32 | tal <- treeAndLeaf(hc) 33 | tal <- formatTree(tal, theme = 5) 34 | 35 | } 36 | \seealso{ 37 | \code{\link[RedeR]{addGraph}} 38 | 39 | \code{\link{treeAndLeaf}} 40 | } 41 | -------------------------------------------------------------------------------- /man/phylo_species.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/phylo_species-data.R 3 | \docType{data} 4 | \name{phylo_species} 5 | \alias{phylo_species} 6 | \title{Species metadata from STRING-db v11} 7 | \format{ 8 | An object of class \code{"data.frame"} 9 | } 10 | \usage{ 11 | data(phylo_species) 12 | } 13 | \description{ 14 | Species metadata used in a phylo object. 15 | } 16 | \references{ 17 | Szklarczyk D. et al. STRING v11: protein-protein association networks with 18 | increased coverage, supporting functional discovery in genome-wide 19 | experimental datasets. Nucleic Acids Res. 47:D607-613, 2019. 20 | } 21 | \keyword{datasets} 22 | -------------------------------------------------------------------------------- /man/phylo_tree.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/phylo_tree-data.R 3 | \docType{data} 4 | \name{phylo_tree} 5 | \alias{phylo_tree} 6 | \title{Species tree from STRING-db v11} 7 | \format{ 8 | An object of class \code{"phylo"} 9 | } 10 | \usage{ 11 | data(phylo_tree) 12 | } 13 | \description{ 14 | A phylo object for the species tree available from the STRING-db v11. 15 | } 16 | \references{ 17 | Szklarczyk D. et al. STRING v11: protein-protein association networks with 18 | increased coverage, supporting functional discovery in genome-wide 19 | experimental datasets. Nucleic Acids Res. 47:D607-613, 2019. 20 | } 21 | \keyword{phylotree} 22 | -------------------------------------------------------------------------------- /man/spdata.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/spdata-data.R 3 | \docType{data} 4 | \name{spdata} 5 | \alias{spdata} 6 | \title{Genome statistics for eukaryotes with complete genome sequence} 7 | \format{ 8 | An object of class \code{"data.frame"} 9 | } 10 | \usage{ 11 | data(spdata) 12 | } 13 | \description{ 14 | Data from the NCBI Genome Database for eukaryotes with complete genome sequence. 15 | The list of organisms were obtained from the KEGG Organisms Database, and 16 | taxonomy IDs were obtained from the NCBI Taxonomy Database. 17 | } 18 | \examples{ 19 | data(spdata) 20 | } 21 | \references{ 22 | NCBI Genome Database 23 | https://www.ncbi.nlm.nih.gov/genome 24 | Accessed: August 15, 2019. 25 | 26 | NCBI Taxonomy Database 27 | https://www.ncbi.nlm.nih.gov/taxonomy 28 | Accessed: August 15, 2019. 29 | 30 | KEGG Organisms Database 31 | https://www.genome.jp/kegg/catalog/org_list.html 32 | Accessed: August 15, 2019. 33 | } 34 | \keyword{datasets} 35 | -------------------------------------------------------------------------------- /man/treeAndLeaf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/treeAndLeaf.R 3 | \name{treeAndLeaf} 4 | \alias{treeAndLeaf} 5 | \title{Layout a TreeAndLeaf diagram.} 6 | \usage{ 7 | treeAndLeaf(obj) 8 | } 9 | \arguments{ 10 | \item{obj}{An object of class 'hclust' or 'phylo'.} 11 | } 12 | \value{ 13 | A tree-and-leaf igraph object. 14 | } 15 | \description{ 16 | This function tranforms hclust and phylo objects into tree-and-leaf 17 | igraph objects. 18 | } 19 | \examples{ 20 | library(RedeR) 21 | rdp <- RedPort() 22 | hc <- hclust(dist(USArrests), "ave") 23 | tal <- treeAndLeaf(hc) 24 | 25 | \dontrun{ 26 | calld(rdp) 27 | addGraph(obj=rdp, tal) 28 | } 29 | 30 | } 31 | \seealso{ 32 | \code{\link{formatTree}} 33 | 34 | \code{\link[stats:hclust]{hclust}} 35 | 36 | \code{\link[ape:as.phylo]{as.phylo}} 37 | 38 | \code{\link[RedeR:addGraph]{addGraph}} 39 | 40 | \code{\link[RedeR:relax]{relax}} 41 | } 42 | -------------------------------------------------------------------------------- /tests/runTests.R: -------------------------------------------------------------------------------- 1 | BiocGenerics:::testPackage("TreeAndLeaf") 2 | -------------------------------------------------------------------------------- /vignettes/PhyloPurple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysbiolab/TreeAndLeaf/7ea90400b10199518cc22ec6ad1075acefdd1550/vignettes/PhyloPurple.png -------------------------------------------------------------------------------- /vignettes/QuakesTree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysbiolab/TreeAndLeaf/7ea90400b10199518cc22ec6ad1075acefdd1550/vignettes/QuakesTree.png -------------------------------------------------------------------------------- /vignettes/TreeAndLeaf.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: '*TreeAndLeaf*: A graph layout strategy for binary trees with focus on the leaves' 3 | author: 'Milena A Cardoso, Luis E A Rizzardi, Leonardo W Kume, Sheyla Trefflich, Clarice Groeneveld, Mauro A A Castro' 4 | date: "`r BiocStyle::doc_date()`" 5 | abstract: "The **TreeAndLeaf** package combines tree and force-directed layout algorithms for drawing binary trees, aiming to represent multiple layers of information onto the leaves." 6 | package: "`r BiocStyle::pkg_ver('TreeAndLeaf')`" 7 | output: 8 | BiocStyle::html_document: 9 | css: custom.css 10 | vignette: > 11 | %\VignetteIndexEntry{TreeAndLeaf: an graph layout to dendrograms.} 12 | %\VignetteEngine{knitr::rmarkdown} 13 | %\VignetteEncoding{UTF-8} 14 | --- 15 | 16 | ```{r, include = FALSE} 17 | knitr::opts_chunk$set( 18 | collapse = TRUE, 19 | comment = "#>" 20 | ) 21 | ``` 22 | 23 | # Overview 24 | 25 | A dendrogram diagram displays binary trees focused on representing 26 | hierarchical relations between the tree elements. A dendrogram contains 27 | nodes, branches (edges), a root, and leaves (**Figure 1A**). The root is where 28 | the branches and nodes come from, indicating the direction to the leaves, 29 | *i.e.*, the terminal nodes. 30 | 31 | Most of the space of a dendrogram layout is used to arrange branches and inner 32 | nodes, with limited space to the leaves. For large dendrograms, the leaf 33 | labels are often squeezed to fit into small slots. Therefore, a dendrogram 34 | may not provide the best layout when the information to be displayed should 35 | highlight the leaves. 36 | 37 | The **TreeAndLeaf** package aims to improve the visualization of the dendrogram 38 | leaves by combining tree and force-directed layout algorithms, shifting the 39 | focus of analysis to the leaves (**Figure 1B**). The package's workflow is 40 | summarized in **Figure 1C**. 41 | 42 |

43 | 44 |

45 | **Figure 1**. **TreeAndLeaf** workflow summary. **(A,B)** The dendrogram in A 46 | is used to construct the graph in B. **(C)** The main input for the **TreeAndLeaf** 47 | package consists of a dendrogram, and then the package transforms the dendrogram 48 | into a graph representation. The finest graph layout is achieved by a two-steps 49 | process, starting with an unrooted tree diagram, which is subsequently relaxed 50 | by a force-directed algorithm applied to the terminal nodes of the tree. The 51 | final *tree-and-leaf* layout varies depending on the initial state, which can be 52 | obtained by other tree layout algorithms (see *section 3* for examples using 53 | *ggtree* layouts to setup the initial state). 54 | 55 | # Quick Start 56 | 57 | This section provides a basic example using the R built-in `USArrests` dataset. 58 | The `USArrests` is a dataframe available in the user's workspace. To know more 59 | about this dataframe, please query `?USArrests` in the R console. We will build 60 | a dendrogram from the `USArrests` dataset, then transform the dendrogram into 61 | a *tree-and-leaf* diagram, and the result will be visualized in the **RedeR** 62 | application. 63 | 64 | ## Package and data requirements 65 | 66 | ```{r, eval=TRUE, message=FALSE} 67 | #-- Libraries required in this section: 68 | #-- TreeAndLeaf(>=1.4.2), RedeR(>=1.40.4), Bioconductor >= 3.13 (R >= 4.0) 69 | # BiocManager::install(c("TreeAndLeaf","RedeR")) 70 | # install.packages(c("igraph","RColorBrewer")) 71 | 72 | #-- Load packages 73 | library("TreeAndLeaf") 74 | library("RedeR") 75 | library("igraph") 76 | library("RColorBrewer") 77 | ``` 78 | 79 | ```{r, eval=TRUE, message=FALSE} 80 | #-- Check data 81 | dim(USArrests) 82 | head(USArrests) 83 | ``` 84 | 85 | ## Building a dendrogram example 86 | 87 | In order to build a dendrogram from the `USArrests` dataset, we need a distance 88 | matrix. We will use the default "euclidean distance" method from the `dist()` 89 | function, and then the "average" method from `hclust()` function to create the 90 | dendrogram. 91 | 92 | ```{r, eval=TRUE, message=FALSE} 93 | hc <- hclust(dist(USArrests), "ave") 94 | plot(hc, main="Dendrogram for the 'USArrests' dataset", 95 | xlab="", sub="") 96 | ``` 97 | 98 | ## Converting the *hclust* object into a *tree-and-leaf* object 99 | 100 | The `treeAndLeaf` function will transform the *hclust* into an *igraph* object, 101 | including some basic graph attributes to display in the **RedeR** application. 102 | 103 | ```{r, eval=FALSE} 104 | #-- Convert the 'hclust' object into a 'tree-and-leaf' object 105 | tal <- treeAndLeaf(hc) 106 | ``` 107 | 108 | ## Setting graph attributes 109 | 110 | The `att.mapv()` function can be used to add external annotations to an *igraph* 111 | object, for example, mapping new variables to the graph vertices. We will add 112 | all `USArrests` variables to the `tal` object. To map one object to another 113 | it is essential to use the same mapping IDs, set by the `refcol` parameter, 114 | which points to a column in the input annotation dataset. In this example, 115 | `refcol = 0` indicates that the `USArrests` rownames will be used as 116 | mapping IDs. To check the IDs in the *igraph* vertices, please type 117 | `V(tal)$name` in the R console. 118 | 119 | ```{r, eval=FALSE} 120 | #--- Map attributes to the tree-and-leaf 121 | #Note: 'refcol = 0' indicates that 'dat' rownames will be used as mapping IDs 122 | tal <- att.mapv(g = tal, dat = USArrests, refcol = 0) 123 | ``` 124 | 125 | Now we use the `att.setv()` wrapper function to set attributes in the 126 | *tree-and-leaf* diagram. To see all attributes available to display in the 127 | **RedeR** application, please type `?addGraph` in the R console. The graph 128 | attributes can also be customized following **igraph** syntax rules. 129 | 130 | ```{r, eval=FALSE} 131 | #--- Set graph attributes using the 'att.setv' wrapper function 132 | pal <- brewer.pal(9, "Reds") 133 | tal <- att.setv(g = tal, from = "Murder", to = "nodeColor", 134 | cols = pal, nquant = 5) 135 | tal <- att.setv(g = tal, from = "UrbanPop", to = "nodeSize", 136 | xlim = c(10, 50, 5), nquant = 5) 137 | 138 | #--- Set graph attributes using 'att.addv' and 'att.adde' functions 139 | tal <- att.addv(tal, "nodeFontSize", value = 15, index = V(tal)$isLeaf) 140 | tal <- att.adde(tal, "edgeWidth", value = 3) 141 | ``` 142 | 143 | ## Plotting a *tree-and-leaf* diagram 144 | 145 | The next steps will call the **RedeR** application, and then display the 146 | *tree-and-leaf* diagram in an interactive R/Java interface. The initial layout 147 | will show an unrooted tree diagram, which will be subsequently relaxed by a 148 | force-directed algorithm applied to the terminal nodes of the tree. 149 | 150 | ```{r, eval=FALSE} 151 | #--- Call RedeR application 152 | rdp <- RedPort() 153 | calld(rdp) 154 | resetd(rdp) 155 | ``` 156 | 157 | ```{r, eval=FALSE} 158 | #--- Send the tree-and-leaf to the interactive R/Java interface 159 | addGraph(obj = rdp, g = tal, gzoom=75) 160 | 161 | #--- Call 'relax' to fine-tune the leaf nodes 162 | relax(rdp, p1=25, p2=200, p3=5, p5=5, ps=TRUE) 163 | ``` 164 | 165 | At this point, the user can interact with the layout process to achieve the 166 | best or desired layout; we suggest fine-tuning the force-directed algorithm 167 | parameters, either through the R/Java interface or the command line relaxation 168 | function. Note that the unroot tree diagram represents the initial state; then 169 | a relaxing process should start until the finest graph layout is achieved. 170 | The final layout varies depending on the initial state, which can also be 171 | adjusted by providing more or less room for the spatial configuration 172 | (*e.g.* via `gzoom` parameter). 173 | 174 | ```{r, eval=FALSE} 175 | #--- Add legends 176 | addLegend.color(obj = rdp, tal, title = "Murder Rate", 177 | position = "topright") 178 | addLegend.size(obj = rdp, tal, title = "Urban Population Size", 179 | position = "bottomright") 180 | ``` 181 | 182 |

183 | 184 |

185 | 186 | # Setting the initial *tree-and-leaf* state with *ggtree* layouts 187 | 188 | The tree diagram represents the initial state of a *tree-and-leaf*, which is then 189 | relaxed by a force-directed algorithm applied to the terminal nodes. Therefore, 190 | the final *tree-and-leaf* layout varies depending on the initial state. The 191 | **treeAndLeaf** package also accepts `ggtree` layouts to setup the initial state. 192 | For example, next we show a tree diagram generated by the **ggtree** package, 193 | and then we apply the *tree-and-leaf* transformation. 194 | 195 | ## Package and data requirements 196 | 197 | ```{r, eval=FALSE, message=FALSE} 198 | #-- Libraries required in this section: 199 | #-- TreeAndLeaf(>=1.4.2), RedeR(>=1.40.4), Bioconductor >= 3.13 (R >= 4.0) 200 | # BiocManager::install(c("TreeAndLeaf","RedeR","ggtree)) 201 | # install.packages(c("igraph","ape", "dendextend", "dplyr", 202 | # "ggplot2", "RColorBrewer")) 203 | 204 | #-- Load packages 205 | library("TreeAndLeaf") 206 | library("RedeR") 207 | library("igraph") 208 | library("ape") 209 | library("ggtree") 210 | library("dendextend") 211 | library("dplyr") 212 | library("ggplot2") 213 | library("RColorBrewer") 214 | ``` 215 | 216 | ## Building and plotting a *phylo* tree with *ggtree* layouts 217 | 218 | ```{r, eval=FALSE} 219 | #--- Generate a random phylo tree 220 | phylo_tree <- rcoal(300) 221 | 222 | #--- Set groups and node sizes 223 | group <- size <- dendextend::cutree(phylo_tree, 10) 224 | group[] <- LETTERS[1:10][group] 225 | size[] <- sample(size) 226 | group.df <- data.frame(label=names(group), group=group, size=size) 227 | phylo_tree <- dplyr::full_join(phylo_tree, group.df, by='label') 228 | 229 | #--- Generate a ggtree with 'daylight' layout 230 | pal <- brewer.pal(10, "Set3") 231 | ggt <- ggtree(phylo_tree, layout = 'daylight', branch.length='none') 232 | 233 | #--- Plot the ggtree 234 | ggt + geom_tippoint(aes(color=group, size=size)) + 235 | scale_color_manual(values=pal) + scale_y_reverse() 236 | ``` 237 | 238 | ## Applying *tree-and-leaf* transformation to *ggtree* layouts 239 | 240 | ```{r, eval=FALSE} 241 | #-- Convert the 'ggtree' object into a 'tree-and-leaf' object 242 | tal <- treeAndLeaf(ggt) 243 | 244 | #--- Map attributes to the tree-and-leaf 245 | #Note: 'refcol = 1' indicates that 'dat' col 1 will be used as mapping IDs 246 | tal <- att.mapv(g = tal, dat = group.df, refcol = 1) 247 | 248 | #--- Set graph attributes using the 'att.setv' wrapper function 249 | tal <- att.setv(g = tal, from = "group", to = "nodeColor", 250 | cols = pal) 251 | tal <- att.setv(g = tal, from = "size", to = "nodeSize", 252 | xlim = c(10, 50, 5)) 253 | 254 | #--- Set graph attributes using 'att.addv' and 'att.adde' functions 255 | tal <- att.addv(tal, "nodeFontSize", value = 1) 256 | tal <- att.addv(tal, "nodeLineWidth", value = 0) 257 | tal <- att.addv(tal, "nodeColor", value = "black", index=!V(tal)$isLeaf) 258 | tal <- att.adde(tal, "edgeWidth", value = 3) 259 | tal <- att.adde(tal, "edgeColor", value = "black") 260 | ``` 261 | 262 | ```{r, eval=FALSE} 263 | #--- Call RedeR application 264 | rdp <- RedPort() 265 | calld(rdp) 266 | resetd(rdp) 267 | ``` 268 | 269 | ```{r, eval=FALSE} 270 | #--- Send the tree-and-leaf to the interactive R/Java interface 271 | addGraph(obj = rdp, g = tal, gzoom=50) 272 | 273 | #--- Select inner nodes, preventing them from relaxing 274 | selectNodes(rdp, V(tal)$name[!V(tal)$isLeaf], anchor=TRUE) 275 | 276 | #--- Call 'relax' to fine-tune the leaf nodes 277 | relax(rdp, p1=25, p2=100, p3=5, p5=1, p8=5, ps=TRUE) 278 | 279 | #--- Add legends 280 | addLegend.color(obj = rdp, tal, title = "Group", 281 | position = "topright",vertical=T) 282 | addLegend.size(obj = rdp, tal, title = "Size", 283 | position = "topleft", 284 | vertical=T, dxtitle=10) 285 | ``` 286 | 287 |

288 | 289 |

290 | 291 | # Case Study 1: visualizing a large dendrogram 292 | 293 | ## Context 294 | 295 | This section follows the same steps described in the *Quick Start*, but 296 | using a larger dendrogram derived from the R built-in `quakes` dataset. 297 | The `quakes` is a dataframe available in the user's workspace. To know more 298 | about this dataframe, please query `?quakes` in the R console. 299 | We will build a dendrogram from the `quakes` dataset, then transform the 300 | dendrogram into a *tree-and-leaf* diagram, and the result will be visualized 301 | in the **RedeR** application. 302 | 303 | ## Package and data requirements 304 | 305 | ```{r, eval=FALSE, message=FALSE} 306 | #-- Libraries required in this section: 307 | #-- TreeAndLeaf(>=1.4.2), RedeR(>=1.40.4), Bioconductor >= 3.13 (R >= 4.0) 308 | # BiocManager::install(c("TreeAndLeaf","RedeR")) 309 | # install.packages(c("igraph", "RColorBrewer")) 310 | 311 | #-- Load packages 312 | library(TreeAndLeaf) 313 | library(RedeR) 314 | library(igraph) 315 | library(RColorBrewer) 316 | ``` 317 | 318 | ```{r echo=TRUE} 319 | #-- Check data 320 | dim(quakes) 321 | head(quakes) 322 | ``` 323 | 324 | ```{r, eval=TRUE, message=FALSE} 325 | #-- Building a large dendrogram 326 | hc <- hclust(dist(quakes), "ave") 327 | plot(hc, main="Dendrogram for the 'quakes' dataset", 328 | xlab="", sub="") 329 | ``` 330 | 331 | ## Building and plotting a large *tree-and-leaf* diagram 332 | 333 | ```{r, eval=FALSE} 334 | #-- Convert the 'hclust' object into a 'tree-and-leaf' object 335 | tal <- treeAndLeaf(hc) 336 | ``` 337 | 338 | ```{r, eval=FALSE} 339 | #--- Map attributes to the tree-and-leaf 340 | #Note: 'refcol = 0' indicates that 'dat' rownames will be used as mapping IDs 341 | tal <- att.mapv(tal, quakes, refcol = 0) 342 | 343 | #--- Set graph attributes using the 'att.setv' wrapper function 344 | pal <- brewer.pal(9, "Greens") 345 | tal <- att.setv(g = tal, from = "mag", to = "nodeColor", 346 | cols = pal, nquant = 10) 347 | tal <- att.setv(g = tal, from = "depth", to = "nodeSize", 348 | xlim = c(40, 120, 20), nquant = 5) 349 | 350 | #--- Set graph attributes using 'att.addv' and 'att.adde' functions 351 | tal <- att.addv(tal, "nodeFontSize", value = 1) 352 | tal <- att.adde(tal, "edgeWidth", value = 10) 353 | ``` 354 | 355 | The next steps will call the **RedeR** application, and then display the 356 | *tree-and-leaf* diagram in an interactive R/Java interface. The initial layout 357 | will show an unrooted tree diagram, which will be subsequently relaxed by a 358 | force-directed algorithm applied to the terminal nodes of the tree. 359 | 360 | ```{r, eval=FALSE} 361 | #--- Call RedeR application 362 | rdp <- RedPort() 363 | calld(rdp) 364 | resetd(rdp) 365 | ``` 366 | 367 | ```{r, eval=FALSE} 368 | #--- Send the tree-and-leaf to the interactive R/Java interface 369 | addGraph(obj = rdp, g = tal, gzoom=10) 370 | 371 | #--- Call 'relax' to fine-tune the leaf nodes 372 | relax(rdp, p1=25, p2=200, p3=10, p4=100, p5=10, ps=TRUE) 373 | ``` 374 | 375 | ```{r, eval=FALSE} 376 | #--- Add legends 377 | addLegend.color(obj = rdp, tal, title = "Richter Magnitude", 378 | position = "bottomright") 379 | addLegend.size(obj = rdp, tal, title = "Depth (km)") 380 | ``` 381 | 382 |

383 | 384 |

385 | 386 | # Case Study 2: visualizing a phylogenetic tree 387 | 388 | ## Context 389 | 390 | This section generates a *tree-and-leaf* diagram from a pre-computed `phylo` 391 | tree object. We will use a phylogenetic tree listing 121 eukaryotes, available 392 | from the **geneplast** package. 393 | 394 | ## Package and data requirements 395 | 396 | ```{r, eval=TRUE, message=FALSE} 397 | #-- Libraries required in this section: 398 | #-- TreeAndLeaf(>=1.4.2), RedeR(>=1.40.4), Bioconductor >= 3.13 (R >= 4.0) 399 | # BiocManager::install(c("TreeAndLeaf","RedeR","geneplast)) 400 | # install.packages(c("igraph","ape", "RColorBrewer")) 401 | 402 | #-- Load packages 403 | library(TreeAndLeaf) 404 | library(RedeR) 405 | library(igraph) 406 | library(ape) 407 | library(geneplast) 408 | library(RColorBrewer) 409 | ``` 410 | 411 | ```{r, eval=TRUE, message=FALSE} 412 | #-- Load data and plot the phylogenetic tree 413 | data("spdata") 414 | data("gpdata.gs") 415 | plot(phyloTree) 416 | ``` 417 | 418 | ## Building and plotting a *tree-and-leaf* from a phylogenetic tree 419 | 420 | ```{r, eval=FALSE} 421 | #--- Drop organisms not listed in the 'spdata' annotation 422 | phyloTree$tip.label <- as.character(phyloTree$tip.label) 423 | tokeep <- phyloTree$tip.label %in% spdata$tax_id 424 | pruned.phylo <- drop.tip(phyloTree, phyloTree$tip.label[!tokeep]) 425 | ``` 426 | 427 | ```{r, eval=FALSE} 428 | #-- Convert the phylogenetic tree into a 'tree-and-leaf' object 429 | tal <- treeAndLeaf(pruned.phylo) 430 | 431 | #--- Map attributes to the tree-and-leaf 432 | #Note: 'refcol = 1' indicates that 'dat' col 1 will be used as mapping IDs 433 | tal <- att.mapv(g = tal, dat = spdata, refcol = 1) 434 | 435 | #--- Set graph attributes using the 'att.setv' wrapper function 436 | pal <- brewer.pal(9, "Purples") 437 | tal <- att.setv(g = tal, from = "genome_size_Mb", 438 | to = "nodeSize", xlim = c(120, 250, 1), nquant = 5) 439 | tal <- att.setv (g = tal, from = "proteins", 440 | to = "nodeColor", nquant = 5, 441 | cols = pal, na.col = "black") 442 | ``` 443 | 444 | ```{r, eval=FALSE} 445 | #--- Add graph attributes using 'att.adde' and 'att.addv' functions 446 | tal <- att.addv(tal, "nodeFontSize", value = 10) 447 | tal <- att.adde(tal, "edgeWidth", value = 20) 448 | 449 | # Set species names to 'nodeAlias' attribute 450 | tal <- att.setv(tal, from = "sp_name", to = "nodeAlias") 451 | 452 | # Select a few names to highlight in the graph 453 | tal <- att.addv(tal, "nodeFontSize", value = 100, 454 | filter=list('name'=sample(pruned.phylo$tip.label,30))) 455 | tal <- att.addv(tal, "nodeFontSize", value = 100, 456 | filter=list('name'="9606")) #Homo sapiens 457 | ``` 458 | 459 | ```{r, eval=FALSE} 460 | # Call RedeR 461 | rdp <- RedPort() 462 | calld(rdp) 463 | resetd(rdp) 464 | 465 | #--- Send the tree-and-leaf to the interactive R/Java interface 466 | addGraph(obj = rdp, g = tal, gzoom=10) 467 | 468 | #--- Call 'relax' to fine-tune the leaf nodes 469 | relax(rdp, ps=TRUE) 470 | ``` 471 | 472 | ```{r, eval=FALSE} 473 | #--- Add legends 474 | addLegend.color(rdp, tal, title = "Proteome Size (n)") 475 | addLegend.size(rdp, tal, title = "Genome Size (Mb)") 476 | ``` 477 | 478 |

479 | 480 |

481 | 482 | # Case Study 3: visualizing a non-binary tree 483 | 484 | ## Context 485 | 486 | The **TreeAndLeaf** package is designed to layout binary trees, but it can also 487 | layout other graph configurations. To exemplify this case, we will use a 488 | larger phylogenetic tree available from the **geneplast** package, and for 489 | which some inner nodes have more than two children, or non-binary nodes. 490 | 491 | ## Package and data requirements 492 | 493 | ```{r, eval=FALSE} 494 | #-- Libraries required in this section: 495 | #-- TreeAndLeaf(>=1.4.2), RedeR(>=1.40.4), Bioconductor >= 3.13 (R >= 4.0) 496 | # BiocManager::install(c("TreeAndLeaf","RedeR","geneplast)) 497 | # install.packages(c("igraph","ape", "RColorBrewer")) 498 | 499 | #-- Load packages 500 | library(TreeAndLeaf) 501 | library(RedeR) 502 | library(igraph) 503 | library(ape) 504 | library(geneplast) 505 | library(RColorBrewer) 506 | ``` 507 | 508 | ```{r, eval=FALSE, message=FALSE} 509 | #-- Load data 510 | data("spdata") 511 | data("phylo_tree") 512 | ``` 513 | 514 | ```{r, eval=FALSE, message=FALSE} 515 | #--- Drop organisms not listed in the 'spdata' annotation 516 | tokeep <- phylo_tree$tip.label %in% spdata$tax_id 517 | pruned.phylo <- drop.tip(phylo_tree, phylo_tree$tip.label[!tokeep]) 518 | ``` 519 | 520 | ## Building and plotting a *tree-and-leaf* for a non-binary tree 521 | 522 | ```{r, eval=FALSE} 523 | #-- Convert the phylogenetic tree into a 'tree-and-leaf' object 524 | tal <- treeAndLeaf(pruned.phylo) 525 | ``` 526 | 527 | ```{r, eval=FALSE} 528 | #--- Map attributes to the tree-and-leaf using "%>%" operator 529 | tal <- tal %>% 530 | att.mapv(dat = spdata, refcol = 1) %>% 531 | att.setv(from = "genome_size_Mb", to = "nodeSize", 532 | xlim = c(120, 250, 1), nquant = 5) %>% 533 | att.setv(from = "proteins", to = "nodeColor", nquant = 5, 534 | cols = brewer.pal(9, "Blues"), na.col = "black") %>% 535 | att.setv(from = "sp_name", to = "nodeAlias") %>% 536 | att.adde(to = "edgeWidth", value = 20) %>% 537 | att.addv(to = "nodeFontSize", value = 10) %>% 538 | att.addv(to = "nodeFontSize", value = 100, 539 | filter = list("name" = sample(pruned.phylo$tip.label, 30))) %>% 540 | att.addv(to = "nodeFontSize", value = 100, 541 | filter = list("name" = "9606")) 542 | ``` 543 | 544 | ```{r, eval=FALSE} 545 | # Call RedeR 546 | rdp <- RedPort() 547 | calld(rdp) 548 | resetd(rdp) 549 | 550 | #--- Send the tree-and-leaf to the interactive R/Java interface 551 | addGraph(obj = rdp, g = tal, gzoom=5) 552 | 553 | #--- Call 'relax' to fine-tune the leaf nodes 554 | relax(rdp, ps=TRUE) 555 | ``` 556 | 557 | ```{r, eval=FALSE} 558 | #--- Add legends 559 | addLegend.color(rdp, tal, title = "Proteome Size (n)") 560 | addLegend.size(rdp, tal, title = "Genome size (Mb)") 561 | ``` 562 | 563 |

564 | 565 |

566 | 567 | # Session information 568 | 569 | ```{r label='Session information', eval=TRUE, echo=FALSE} 570 | sessionInfo() 571 | ``` 572 | -------------------------------------------------------------------------------- /vignettes/USAReds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysbiolab/TreeAndLeaf/7ea90400b10199518cc22ec6ad1075acefdd1550/vignettes/USAReds.png -------------------------------------------------------------------------------- /vignettes/custom.css: -------------------------------------------------------------------------------- 1 | 2 | .title { 3 | margin: 1.2em 0 0.6em 0; 4 | } 5 | 6 | h1, h2, h3, h4, h5, h6 { 7 | padding: 0 0 0 0; 8 | text-indent: 0; 9 | margin: 1.2em 0 0.6em 0; 10 | } 11 | 12 | p { 13 | padding: 0 0 0 0; 14 | } 15 | 16 | pre, code { 17 | padding: 0 0 0 0; 18 | margin: 0 0 0.5em 0; 19 | } 20 | 21 | P > img { 22 | padding: 0 0 0 0; 23 | margin: 35px auto 15px auto; 24 | } 25 | 26 | span.header-section-number { 27 | width: 35px; 28 | } 29 | 30 | div#TOC > ul, ul { 31 | padding: 0 15px 0 35px; 32 | } 33 | -------------------------------------------------------------------------------- /vignettes/ggtree_tal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysbiolab/TreeAndLeaf/7ea90400b10199518cc22ec6ad1075acefdd1550/vignettes/ggtree_tal.png -------------------------------------------------------------------------------- /vignettes/nBinPhylo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysbiolab/TreeAndLeaf/7ea90400b10199518cc22ec6ad1075acefdd1550/vignettes/nBinPhylo.png -------------------------------------------------------------------------------- /vignettes/overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sysbiolab/TreeAndLeaf/7ea90400b10199518cc22ec6ad1075acefdd1550/vignettes/overview.png --------------------------------------------------------------------------------