#### Update layout.R

William Lee authored on 29/12/2021 07:23:29
Showing1 changed files

 ... ... `@@ -3,9 +3,15 @@` 3 3 ` ##' ` 4 4 ` ##' @title rotate_tree` 5 5 ` ##' @param treeview tree view` 6 `-##' @param angle angle` 6 `+##' @param angle the angle of rotation` 7 7 ` ##' @return updated tree view` 8 8 ` ##' @export` 9 `+##' @examples` 10 `+##' tree <- rtree(15)` 11 `+##' p <- ggtree(tree) + geom_tiplab()` 12 `+##' p2 <- open_tree(p, 180)` 13 `+##' p3 <- rotate_tree(p2, 180)` 14 `+##' p3` 9 15 ` ##' @author Guangchuang Yu` 10 16 ` rotate_tree <- function(treeview, angle) {` 11 17 ` treeview <- treeview + coord_polar(theta='y', start=(angle-90)/180*pi, -1)` ... ... `@@ -14,15 +20,19 @@ rotate_tree <- function(treeview, angle) {` 14 20 ` return(treeview)` 15 21 ` }` 16 22 ` ` 17 `-##' open tree with specific angle` 23 `+##' transform a tree in either rectangular or circular layout into the fan layout that opens with a specific angle` 18 24 ` ##'` 19 25 ` ##' ` 20 26 ` ##' @title open_tree` 21 27 ` ##' @param treeview tree view` 22 `-##' @param angle angle` 28 `+##' @param angle open the tree at a specific angle` 23 29 ` ##' @return updated tree view` 24 30 ` ##' @importFrom ggplot2 scale_y_continuous` 25 31 ` ##' @export` 32 `+##' @examples` 33 `+##' tree <- rtree(15)` 34 `+##' p <- ggtree(tree) + geom_tiplab()` 35 `+##' open_tree(p, 180)` 26 36 ` ##' @author Guangchuang Yu` 27 37 ` open_tree <- function(treeview, angle) {` 28 38 ` p <- treeview + layout_circular()` ... ... `@@ -40,24 +50,44 @@ open_tree <- function(treeview, angle) {` 40 50 ` return(p)` 41 51 ` }` 42 52 ` ` 53 `+##' transform circular/fan layout to rectangular layout` 54 `+##'` 55 `+##' ` 43 56 ` ##' @title layout_rectangular` 44 57 ` ##' @rdname tree-layout` 45 58 ` ##' @export` 59 `+##' @examples` 60 `+##' tree <- rtree(20)` 61 `+##' ggtree(tree, layout = "circular") + layout_rectangular()` 46 62 ` layout_rectangular <- function() {` 47 63 ` layout_ggtree('rectangular')` 48 64 ` }` 49 65 ` ` 66 `+##' transform rectangular layout to circular layout` 67 `+##'` 68 `+##' ` 50 69 ` ##' @title layout_circular` 51 70 ` ##' @rdname tree-layout` 52 71 ` ##' @export` 72 `+##' @examples` 73 `+##' tree <- rtree(20)` 74 `+##' p <- ggtree(tree)` 75 `+##' p + layout_circular()` 53 76 ` layout_circular <- function() {` 54 77 ` layout_ggtree('circular')` 55 78 ` }` 56 79 ` ` 80 `+##' transform rectangular/circular layout to inward_circular layout` 81 `+##'` 82 `+##' ` 57 83 ` ##' @title layout_inward_circular` 58 `-##' @param xlim x limits` 84 `+##' @param xlim setting x limits, which will affect the center space of the tree` 59 85 ` ##' @rdname tree-layout` 60 86 ` ##' @export` 87 `+##' @examples` 88 `+##' tree <- rtree(20)` 89 `+##' p <- ggtree(tree)` 90 `+##' p + layout_inward_circular(xlim=4) + geom_tiplab(hjust=1)` 61 91 ` layout_inward_circular <- function(xlim = NULL) {` 62 92 ` if (!is.null(xlim) && length(xlim) == 1) {` 63 93 ` xlim <- c(xlim, 0)` ... ... `@@ -65,20 +95,31 @@ layout_inward_circular <- function(xlim = NULL) {` 65 95 ` layout_ggtree(layout = "inward_circular", xlim = xlim)` 66 96 ` }` 67 97 ` ` 98 `+##' transform rectangular/circular layout to fan layout` 99 `+##'` 100 `+##' ` 68 101 ` ##' @title layout_fan` 69 102 ` ##' @rdname tree-layout` 70 103 ` ##' @param angle open tree at specific angle` 71 104 ` ##' @export` 105 `+##' @examples` 106 `+##' tree <- rtree(20)` 107 `+##' p <- ggtree(tree)` 108 `+##' p + layout_fan(angle=90)` 72 109 ` layout_fan <- function(angle = 180) {` 73 110 ` layout_ggtree('fan', angle = angle)` 74 111 ` }` 75 `- ` 76 `-##' tree layout` 112 `+` 113 `+##' transform rectangular layout to dendrogram layout` 77 114 ` ##'` 78 115 ` ##'` 79 116 ` ##' @title layout_dendrogram` 80 117 ` ##' @rdname tree-layout` 81 118 ` ##' @export` 119 `+##' @examples` 120 `+##' tree <- rtree(20)` 121 `+##' p <- ggtree(tree)` 122 `+##' p + p + layout_dendrogram()` 82 123 ` ##' @author Guangchuang Yu` 83 124 ` layout_dendrogram <- function() {` 84 125 ` layout_ggtree('dendrogram')`