diff --git a/NAMESPACE b/NAMESPACE index ea22b809..69b807a3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -124,6 +124,8 @@ S3method(fortify_data_frame,Matrix) S3method(fortify_data_frame,character) S3method(fortify_data_frame,complex) S3method(fortify_data_frame,default) +S3method(fortify_data_frame,dendrogram) +S3method(fortify_data_frame,hclust) S3method(fortify_data_frame,logical) S3method(fortify_data_frame,matrix) S3method(fortify_data_frame,numeric) @@ -409,7 +411,6 @@ export(continuous_limits) export(cross_link) export(cross_mark) export(cross_none) -export(dendrogram_data) export(draw_key_draw) export(draw_key_draw2) export(element_curve) diff --git a/R/align-dendrogram.R b/R/align-dendrogram.R index 7688629c..f67f0305 100644 --- a/R/align-dendrogram.R +++ b/R/align-dendrogram.R @@ -16,35 +16,12 @@ #' [`geom_segment`][ggplot2::geom_segment] layer with a data frame of the `edge` #' coordinates will be added when `plot_dendrogram = TRUE`. #' -#' dendrogram `node` and `edge` contains following columns: -#' -#' - `.panel`: Tree branch groups, used to create ggplot2 facet. Similar with -#' `panel` column, but always give the correct branch for usage of -#' the ggplot facet. -#' - `.names` and `.index`: a character names (only applicable when names -#' exists) and an integer index of the original data. -#' - `label`: node label text -#' - `x` and `y`: x-axis and y-axis coordinates for current node or the start -#' node of the current edge. -#' - `xend` and `yend`: the x-axis and y-axis coordinates of the terminal node -#' for current edge. -#' - `branch`: which branch current node or edge is. You can use this column -#' to color different groups. -#' - `leaf`: A logical value indicates whether current node is a leaf. -#' - `panel`: which panel current node is, if we split the plot into panel -#' using [`facet_grid`][ggplot2::facet_grid], this column will show -#' which panel current node or edge is from. Note: some nodes may -#' fall outside panel (between two panel), so there are possible -#' `NA` values in this column. -#' - `panel1` and `panel2`: The panel1 and panel2 variables have the same -#' functionality as `panel`, but they are specifically for the `edge` data -#' and correspond to both nodes of each edge. -#' +#' See [`fortify_data_frame.dendrogram()`] for details. #' @param merge_dendrogram A single boolean value, indicates whether we should #' merge multiple dendrograms, only used when previous groups have been #' established. Default: `FALSE`. #' @inheritParams align_hclust -#' @inheritParams dendrogram_data +#' @inheritParams fortify_data_frame.dendrogram #' @inheritParams ggalign #' @inheritSection align Discrete Axis Alignment #' @examples @@ -173,7 +150,7 @@ AlignDendro <- ggproto("AlignDendro", AlignHclust, tree <- .subset2(statistics, i) n <- stats::nobs(tree) end <- start + n - data[[i]] <- dendrogram_data( + data[[i]] <- fortify_data_frame( tree, priority = priority, center = center, @@ -186,11 +163,19 @@ AlignDendro <- ggproto("AlignDendro", AlignHclust, ) start <- end } - data <- lapply(list_transpose(data), function(dat) { - ans <- vec_rbind(!!!dat, .names_to = "parent") - ans$ggpanel <- factor(.subset2(ans, "ggpanel"), branches) - ans - }) + data <- lapply( + list( + node = data, + edge = lapply(data, ggalign_attr, "edge") + ), + function(dat) { + ans <- vec_rbind(!!!dat, .names_to = "parent") + ans$.panel <- factor(.subset2(ans, ".panel"), branches) + ans + } + ) + edge <- .subset2(data, "edge") + node <- .subset2(data, "node") } else { if (nlevels(panel) > 1L && type == "triangle" && self$in_linear) { cli_warn(c(paste( @@ -199,7 +184,7 @@ AlignDendro <- ggproto("AlignDendro", AlignHclust, ), i = "will use {.filed rectangle} dendrogram instead")) type <- "rectangle" } - data <- dendrogram_data( + data <- fortify_data_frame( statistics, priority = priority, center = center, @@ -210,11 +195,9 @@ AlignDendro <- ggproto("AlignDendro", AlignHclust, root = root, double = self$in_linear ) + edge <- ggalign_attr(data, "edge") + node <- data } - node <- .subset2(data, "node") - edge <- .subset2(data, "edge") - node <- rename(node, c(ggpanel = ".panel", index = ".index")) - edge <- rename(edge, c(ggpanel = ".panel")) # add names if (!is.null(self$labels)) { diff --git a/R/align-hclust.R b/R/align-hclust.R index 17632e9e..a46a9c23 100644 --- a/R/align-hclust.R +++ b/R/align-hclust.R @@ -28,9 +28,7 @@ #' (the height at which to cut the tree). By default, #' [`cutree()`][stats::cutree()] is used. #' @inheritSection align Discrete Axis Alignment -#' @seealso -#' - [`dendrogram_data()`] -#' - [`hclust2()`] +#' @seealso [`hclust2()`] #' @examples #' # align_hclust won't add a dendrogram #' ggheatmap(matrix(rnorm(81), nrow = 9)) + diff --git a/R/align-phylo.R b/R/align-phylo.R index 95f6a767..d5a128cc 100644 --- a/R/align-phylo.R +++ b/R/align-phylo.R @@ -182,15 +182,15 @@ AlignPhylo <- ggproto("AlignPhylo", Align, summary_align = function(self) c(TRUE, FALSE) ) -#' @inherit fortify_data_frame.default -#' @inheritParams dendrogram_data +#' @inherit fortify_data_frame.default title description +#' @inheritParams rlang::args_dots_empty +#' @inheritParams fortify_data_frame.dendrogram #' @param tree_type A single string, one of #' `r oxford_or(c("phylogram", "cladogram"))`, indicating the type of tree. #' Usually, you don't need to modify this. #' @param tip_pos The x-coordinates of the tip. Must be the same length #' of the number of tips in `tree`. -#' @details -#' A `data frame` with the node coordinates: +#' @return A `data frame` with the node coordinates: #' - `.index`: the original index in the tree for the the tip/node. #' - `label`: the tip/node label text. #' - `x` and `y`: x-axis and y-axis coordinates for the tip/node. @@ -205,6 +205,7 @@ AlignPhylo <- ggproto("AlignPhylo", Align, fortify_data_frame.phylo <- function(data, ..., type = "rectangle", center = FALSE, tree_type = NULL, tip_pos = NULL) { + rlang::check_dots_empty() type <- arg_match0(type, c("rectangle", "triangle")) rectangle <- type == "rectangle" edge <- data$edge diff --git a/R/dendrogram.R b/R/dendrogram.R index 29f8d0c5..1ea9f7cc 100644 --- a/R/dendrogram.R +++ b/R/dendrogram.R @@ -109,10 +109,10 @@ make_dist <- function(matrix, distance, use_missing, d } -#' Dengrogram x and y coordinates +#' @inherit fortify_data_frame.default title description #' -#' @param tree A [hclust][stats::hclust] or a [dendrogram][stats::as.dendrogram] -#' object. +#' @param data A [`hclust`][stats::hclust] or a +#' [`dendrogram`][stats::as.dendrogram] object. #' @param priority A string of "left" or "right". if we draw from right to left, #' the left will override the right, so we take the `"left"` as the priority. If #' we draw from `left` to `right`, the right will override the left, so we take @@ -135,50 +135,55 @@ make_dist <- function(matrix, distance, use_missing, #' should be doubled when segments span multiple branches. If `TRUE`, the #' horizontal lines will be repeated for each branch that the segment spans. If #' `FALSE`, only one horizontal line will be drawn. -#' @return A list of 2 data.frame. One for node coordinates, another for edge -#' coordinates. -#' `node` and tree segments `edge` coordinates contains following columns: -#' - `index`: the original index in the tree for the current node +#' @return A `data frame` with the node coordinates: +#' - `.panel`: Similar with `panel` column, but always give the correct +#' branch for usage of the ggplot facet. +#' - `.index`: the original index in the tree for the the node #' - `label`: node label text -#' - `x` and `y`: x-axis and y-axis coordinates for current node or the start -#' node of the current edge. -#' - `xend` and `yend`: the x-axis and y-axis coordinates of the terminal node -#' for current edge. -#' - `branch`: which branch current node or edge is. You can use this column -#' to color different groups. -#' - `panel`: which panel current node is, if we split the plot into panel +#' - `x` and `y`: x-axis and y-axis coordinates for the node +#' - `branch`: which branch the node is. You can use this column to color +#' different groups. +#' - `panel`: which panel the node is, if we split the plot into panel #' using [facet_grid][ggplot2::facet_grid], this column will show -#' which panel current node or edge is from. Note: some nodes may +#' which panel the node is from. Note: some nodes may #' fall outside panel (between two panels), so there are possible #' `NA` values in this column. -#' - `ggpanel`: Similar with `panel` column, but always give the correct +#' - `leaf`: A logical value indicates whether the node is a leaf. +#' @section ggalign attributes: +#' `edge`: A `data frame` for edge coordinates: +#' - `.panel`: Similar with `panel` column, but always give the correct #' branch for usage of the ggplot facet. -#' - `panel1` and `panel2`: The panel1 and panel2 variables have the same +#' - `x` and `y`: x-axis and y-axis coordinates for the start node of the edge. +#' - `xend` and `yend`: the x-axis and y-axis coordinates of the terminal node +#' for edge. +#' - `branch`: which branch the edge is. You can use this column to color +#' different groups. +#' - `panel1` and `panel2`: The panel1 and panel2 columns have the same #' functionality as `panel`, but they are specifically for the `edge` data #' and correspond to both nodes of each edge. -#' - `leaf`: A logical value indicates whether current node is a leaf. #' @examples -#' dendrogram_data(hclust(dist(USArrests), "ave")) +#' fortify_data_frame(hclust(dist(USArrests), "ave")) #' @importFrom grid is.unit #' @importFrom stats order.dendrogram #' @importFrom rlang arg_match0 +#' @family fortify_data_frame methods #' @export -dendrogram_data <- function(tree, - priority = "right", - center = FALSE, - type = "rectangle", - leaf_pos = NULL, - leaf_braches = NULL, - reorder_branches = TRUE, - branch_gap = NULL, - root = NULL, - double = TRUE) { - dend <- check_dendrogram(tree) +fortify_data_frame.dendrogram <- function(data, ..., + priority = "right", + center = FALSE, + type = "rectangle", + leaf_pos = NULL, + leaf_braches = NULL, + reorder_branches = TRUE, + branch_gap = NULL, + root = NULL, + double = TRUE) { + rlang::check_dots_empty() assert_bool(center) assert_bool(reorder_branches) type <- arg_match0(type, c("rectangle", "triangle")) priority <- arg_match0(priority, c("left", "right")) - N <- stats::nobs(dend) + N <- stats::nobs(data) rectangle <- type == "rectangle" if (is.null(leaf_pos)) { leaf_pos <- seq_len(N) @@ -209,7 +214,7 @@ dendrogram_data <- function(tree, } if (!is.null(leaf_braches) && reorder_branches) { - leaf_braches <- .subset(leaf_braches, order.dendrogram(dend)) + leaf_braches <- .subset(leaf_braches, order.dendrogram(data)) } # check `branch_gap` @@ -239,7 +244,7 @@ dendrogram_data <- function(tree, branch_levels <- NULL last_branch <- root total_gap <- 0 - .dendrogram_data <- function(dend, from_root = TRUE) { + dendrogram_data <- function(dend, from_root = TRUE) { if (stats::is.leaf(dend)) { # base version index <- as.integer(dend) # the column index of the original data y <- attr(dend, "height") %||% 0 @@ -282,7 +287,7 @@ dendrogram_data <- function(tree, # for the children nodes --------------------------------- data <- list_transpose( - lapply(dend, .dendrogram_data, from_root = FALSE) + lapply(dend, dendrogram_data, from_root = FALSE) ) # node should be the direct children @@ -444,7 +449,7 @@ dendrogram_data <- function(tree, cli_abort("{.arg dend} must be a {.cls dendrogram} object") } } - ans <- .dendrogram_data(dend) + ans <- dendrogram_data(data) node <- .subset2(ans, "node") edge <- .subset2(ans, "edge") @@ -460,7 +465,16 @@ dendrogram_data <- function(tree, edge$branch <- factor(.subset2(edge, "branch"), branch_levels) edge$ggpanel <- factor(.subset2(edge, "ggpanel"), panel_levels) } - list(node = node, edge = edge) + node <- rename(node, c(ggpanel = ".panel", index = ".index")) + edge <- rename(edge, c(ggpanel = ".panel")) + ggalign_attr_set(node, list(edge = edge)) +} + +#' @param ... Additional arguments passed to `dendrogram` method. +#' @export +#' @rdname fortify_data_frame.dendrogram +fortify_data_frame.hclust <- function(data, ...) { + fortify_data_frame.dendrogram(stats::as.dendrogram(data), ...) } #' @param ggpanels Won't be `NA` @@ -584,18 +598,3 @@ tree_branch_heights <- function(dend) { ) } } - -#' @importFrom rlang caller_arg caller_env -check_dendrogram <- function(tree, arg = caller_arg(tree), - call = caller_call()) { - if (inherits(tree, "hclust")) { - stats::as.dendrogram(tree) - } else if (inherits(tree, "dendrogram")) { - tree - } else { - cli_abort(paste( - "{.arg {arg}} must be a {.cls hclust}", - "or a {.cls dendrogram} object." - ), call = call) - } -} diff --git a/R/fortify-data-frame.R b/R/fortify-data-frame.R index 9d6969b3..a286eba6 100644 --- a/R/fortify-data-frame.R +++ b/R/fortify-data-frame.R @@ -6,20 +6,20 @@ #' This function converts various objects to a data frame. #' #' @param data An object to be converted to a data frame. -#' @inheritParams rlang::args_dots_used +#' @param ... Arguments passed to methods. #' @return A data frame. #' @seealso #' - [`fortify_data_frame.default()`] -#' - [`fortify_data_frame.character()`] -#' - [`fortify_data_frame.numeric()`] +#' - [`fortify_data_frame.character()`]/[`fortify_data_frame.numeric()`] #' - [`fortify_data_frame.matrix()`] +#' - [`fortify_data_frame.dendrogram()`] #' @export fortify_data_frame <- function(data, ...) { - rlang::check_dots_used() UseMethod("fortify_data_frame") } #' @inherit fortify_data_frame +#' @param ... Additional arguments passed to [`fortify()`][ggplot2::fortify]. #' @details #' By default, it calls [`fortify()`][ggplot2::fortify] to build the #' data frame. @@ -29,10 +29,10 @@ fortify_data_frame.default <- function(data, ...) { ggplot2::fortify(model = data, ...) } -#' @inherit fortify_data_frame.default -#' @details -#' When `data` is an atomic vector, it'll be converted to a data frame with -#' following columns: +#' @inherit fortify_data_frame.default title description +#' @param data An object to be converted to a data frame. +#' @inheritParams rlang::args_dots_empty +#' @return A data frame with following columns: #' #' - `.names`: the names for the vector (only applicable if names exist). #' - `value`: the actual value of the vector. @@ -40,34 +40,37 @@ fortify_data_frame.default <- function(data, ...) { #' @family fortify_data_frame methods #' @export fortify_data_frame.character <- function(data, ...) { + rlang::check_dots_empty() ans <- list(.names = vec_names(data), value = data) if (is.null(.subset2(ans, ".names"))) ans$.names <- NULL new_data_frame(ans) } -#' @inherit fortify_data_frame.character -#' @family fortify_data_frame methods +#' @rdname fortify_data_frame.character #' @export fortify_data_frame.numeric <- fortify_data_frame.character -#' @inherit fortify_data_frame.character -#' @family fortify_data_frame methods +#' @rdname fortify_data_frame.character #' @export fortify_data_frame.logical <- fortify_data_frame.character -#' @inherit fortify_data_frame.character -#' @family fortify_data_frame methods +#' @rdname fortify_data_frame.character #' @export fortify_data_frame.complex <- fortify_data_frame.character #' @export -fortify_data_frame.waiver <- function(data, ...) data +fortify_data_frame.waiver <- function(data, ...) { + rlang::check_dots_empty() + data +} #' @export -fortify_data_frame.NULL <- function(data, ...) data +fortify_data_frame.NULL <- fortify_data_frame.waiver -#' @inherit fortify_data_frame.default -#' @details +#' @inherit fortify_data_frame.default title description +#' @param data A matrix-like object. +#' @inheritParams rlang::args_dots_empty +#' @return #' Matrix will be transformed into a long-form data frame, where each row #' represents a unique combination of matrix indices and their corresponding #' values. The resulting data frame will contain the following columns: @@ -83,6 +86,7 @@ fortify_data_frame.NULL <- function(data, ...) data #' @family fortify_data_frame methods #' @export fortify_data_frame.matrix <- function(data, ...) { + rlang::check_dots_empty() row_nms <- vec_names(data) col_nms <- colnames(data) data <- new_data_frame(list( @@ -98,11 +102,11 @@ fortify_data_frame.matrix <- function(data, ...) { #' @export #' @rdname fortify_data_frame.matrix fortify_data_frame.DelayedMatrix <- function(data, ...) { - fortify_data_frame(as.matrix(data)) + fortify_data_frame(as.matrix(data), ...) } #' @export #' @rdname fortify_data_frame.matrix fortify_data_frame.Matrix <- function(data, ...) { - fortify_data_frame(as.matrix(data)) + fortify_data_frame(as.matrix(data), ...) } diff --git a/R/fortify-matrix.R b/R/fortify-matrix.R index a6a65b22..082f47d3 100644 --- a/R/fortify-matrix.R +++ b/R/fortify-matrix.R @@ -6,7 +6,7 @@ #' This function converts various objects into a matrix format. #' #' @param data An object to be converted to a matrix. -#' @inheritParams rlang::args_dots_used +#' @param ... Arguments passed to methods. #' @return A matrix. #' @seealso #' - [`fortify_matrix.default()`] @@ -14,17 +14,19 @@ #' - [`fortify_matrix.GISTIC()`] #' @export fortify_matrix <- function(data, ...) { - rlang::check_dots_used() UseMethod("fortify_matrix") } -#' @inherit fortify_matrix -#' @description +#' @inherit fortify_matrix title description return +#' @inheritParams rlang::args_dots_empty +#' @inheritParams fortify_matrix +#' @details #' By default, it calls [`as.matrix()`] to build a matrix. #' @family fortify_matrix methods #' @importFrom rlang try_fetch #' @export fortify_matrix.default <- function(data, ...) { + rlang::check_dots_empty() try_fetch( as.matrix(data), error = function(cnd) { @@ -38,23 +40,29 @@ fortify_matrix.default <- function(data, ...) { } #' @export -fortify_matrix.matrix <- function(data, ...) data +fortify_matrix.matrix <- function(data, ...) { + rlang::check_dots_empty() + data +} #' @export -fortify_matrix.waiver <- function(data, ...) data +fortify_matrix.waiver <- fortify_matrix.matrix #' @export -fortify_matrix.NULL <- function(data, ...) NULL +fortify_matrix.NULL <- fortify_matrix.matrix #' @export -fortify_matrix.function <- function(data, ...) data +fortify_matrix.function <- fortify_matrix.matrix #' @export -fortify_matrix.formula <- function(data, ...) rlang::as_function(data) +fortify_matrix.formula <- function(data, ...) { + rlang::check_dots_empty() + rlang::as_function(data) +} -#' @inherit fortify_matrix -#' @inheritParams fortify_matrix.default -#' @param ... Not used currently. +#' @inherit fortify_matrix title description return +#' @param data A [`MAF`][maftools::read.maf] object. +#' @inheritParams rlang::args_dots_empty #' @param genes An atomic character defines the genes to draw. #' @param n_top A single number indicates how many top genes to be drawn. #' @param remove_empty_samples A single boolean value indicating whether to drop @@ -84,6 +92,7 @@ fortify_matrix.MAF <- function(data, ..., genes = NULL, n_top = NULL, remove_empty_samples = TRUE, collapse_vars = TRUE, use_syn = TRUE) { + rlang::check_dots_empty() rlang::check_installed( "maftools", "to make alterations matrix from `MAF` object" ) @@ -240,9 +249,9 @@ fortify_matrix.MAF <- function(data, ..., genes = NULL, n_top = NULL, )) } -#' @inherit fortify_matrix -#' @inheritParams fortify_matrix.default -#' @param ... Not used currently. +#' @inherit fortify_matrix title description return +#' @inheritParams rlang::args_dots_empty +#' @param data A [`GISTIC`][maftools::readGistic] object. #' @param n_top A single number indicates how many top bands to be drawn. #' @param bands An atomic character defines the bands to draw. #' @param ignored_bands An atomic character defines the bands to be ignored. @@ -264,6 +273,7 @@ fortify_matrix.MAF <- function(data, ..., genes = NULL, n_top = NULL, fortify_matrix.GISTIC <- function(data, ..., n_top = NULL, bands = NULL, ignored_bands = NULL, sample_anno = NULL, remove_empty_samples = TRUE) { + rlang::check_dots_empty() rlang::check_installed( "maftools", "to make CNV matrix from `GISTIC` object" diff --git a/man/align_dendro.Rd b/man/align_dendro.Rd index 49cb37c2..203b21e0 100644 --- a/man/align_dendro.Rd +++ b/man/align_dendro.Rd @@ -125,30 +125,7 @@ in \code{\link[=ggalign_attr]{ggalign}} attribute, in addition, a \code{\link[ggplot2:geom_segment]{geom_segment}} layer with a data frame of the \code{edge} coordinates will be added when \code{plot_dendrogram = TRUE}. -dendrogram \code{node} and \code{edge} contains following columns: -\itemize{ -\item \code{.panel}: Tree branch groups, used to create ggplot2 facet. Similar with -\code{panel} column, but always give the correct branch for usage of -the ggplot facet. -\item \code{.names} and \code{.index}: a character names (only applicable when names -exists) and an integer index of the original data. -\item \code{label}: node label text -\item \code{x} and \code{y}: x-axis and y-axis coordinates for current node or the start -node of the current edge. -\item \code{xend} and \code{yend}: the x-axis and y-axis coordinates of the terminal node -for current edge. -\item \code{branch}: which branch current node or edge is. You can use this column -to color different groups. -\item \code{leaf}: A logical value indicates whether current node is a leaf. -\item \code{panel}: which panel current node is, if we split the plot into panel -using \code{\link[ggplot2:facet_grid]{facet_grid}}, this column will show -which panel current node or edge is from. Note: some nodes may -fall outside panel (between two panel), so there are possible -\code{NA} values in this column. -\item \code{panel1} and \code{panel2}: The panel1 and panel2 variables have the same -functionality as \code{panel}, but they are specifically for the \code{edge} data -and correspond to both nodes of each edge. -} +See \code{\link[=fortify_data_frame.dendrogram]{fortify_data_frame.dendrogram()}} for details. } \section{Discrete Axis Alignment}{ diff --git a/man/align_hclust.Rd b/man/align_hclust.Rd index 44c82072..5380e0fa 100644 --- a/man/align_hclust.Rd +++ b/man/align_hclust.Rd @@ -89,8 +89,5 @@ ggheatmap(matrix(rnorm(81), nrow = 9)) + align_hclust(k = 3L) } \seealso{ -\itemize{ -\item \code{\link[=dendrogram_data]{dendrogram_data()}} -\item \code{\link[=hclust2]{hclust2()}} -} +\code{\link[=hclust2]{hclust2()}} } diff --git a/man/fortify_data_frame.Rd b/man/fortify_data_frame.Rd index 8095730e..13bd8313 100644 --- a/man/fortify_data_frame.Rd +++ b/man/fortify_data_frame.Rd @@ -22,8 +22,8 @@ This function converts various objects to a data frame. \seealso{ \itemize{ \item \code{\link[=fortify_data_frame.default]{fortify_data_frame.default()}} -\item \code{\link[=fortify_data_frame.character]{fortify_data_frame.character()}} -\item \code{\link[=fortify_data_frame.numeric]{fortify_data_frame.numeric()}} +\item \code{\link[=fortify_data_frame.character]{fortify_data_frame.character()}}/\code{\link[=fortify_data_frame.numeric]{fortify_data_frame.numeric()}} \item \code{\link[=fortify_data_frame.matrix]{fortify_data_frame.matrix()}} +\item \code{\link[=fortify_data_frame.dendrogram]{fortify_data_frame.dendrogram()}} } } diff --git a/man/fortify_data_frame.character.Rd b/man/fortify_data_frame.character.Rd index d76daf7d..611ef32b 100644 --- a/man/fortify_data_frame.character.Rd +++ b/man/fortify_data_frame.character.Rd @@ -2,37 +2,40 @@ % Please edit documentation in R/fortify-data-frame.R \name{fortify_data_frame.character} \alias{fortify_data_frame.character} +\alias{fortify_data_frame.numeric} +\alias{fortify_data_frame.logical} +\alias{fortify_data_frame.complex} \title{Build a data frame} \usage{ \method{fortify_data_frame}{character}(data, ...) + +\method{fortify_data_frame}{numeric}(data, ...) + +\method{fortify_data_frame}{logical}(data, ...) + +\method{fortify_data_frame}{complex}(data, ...) } \arguments{ \item{data}{An object to be converted to a data frame.} -\item{...}{Arguments passed to methods.} +\item{...}{These dots are for future extensions and must be empty.} } \value{ -A data frame. +A data frame with following columns: +\itemize{ +\item \code{.names}: the names for the vector (only applicable if names exist). +\item \code{value}: the actual value of the vector. +} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} This function converts various objects to a data frame. } -\details{ -When \code{data} is an atomic vector, it'll be converted to a data frame with -following columns: -\itemize{ -\item \code{.names}: the names for the vector (only applicable if names exist). -\item \code{value}: the actual value of the vector. -} -} \seealso{ Other fortify_data_frame methods: -\code{\link{fortify_data_frame.complex}()}, \code{\link{fortify_data_frame.default}()}, -\code{\link{fortify_data_frame.logical}()}, -\code{\link{fortify_data_frame.matrix}()}, -\code{\link{fortify_data_frame.numeric}()} +\code{\link{fortify_data_frame.dendrogram}()}, +\code{\link{fortify_data_frame.matrix}()} } \concept{fortify_data_frame methods} diff --git a/man/fortify_data_frame.complex.Rd b/man/fortify_data_frame.complex.Rd deleted file mode 100644 index 5d63d44d..00000000 --- a/man/fortify_data_frame.complex.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/fortify-data-frame.R -\name{fortify_data_frame.complex} -\alias{fortify_data_frame.complex} -\title{Build a data frame} -\usage{ -\method{fortify_data_frame}{complex}(data, ...) -} -\arguments{ -\item{data}{An object to be converted to a data frame.} - -\item{...}{Arguments passed to methods.} -} -\value{ -A data frame. -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - -This function converts various objects to a data frame. -} -\details{ -When \code{data} is an atomic vector, it'll be converted to a data frame with -following columns: -\itemize{ -\item \code{.names}: the names for the vector (only applicable if names exist). -\item \code{value}: the actual value of the vector. -} -} -\seealso{ -Other fortify_data_frame methods: -\code{\link{fortify_data_frame.character}()}, -\code{\link{fortify_data_frame.default}()}, -\code{\link{fortify_data_frame.logical}()}, -\code{\link{fortify_data_frame.matrix}()}, -\code{\link{fortify_data_frame.numeric}()} -} -\concept{fortify_data_frame methods} diff --git a/man/fortify_data_frame.default.Rd b/man/fortify_data_frame.default.Rd index 04f4529d..63d7a40d 100644 --- a/man/fortify_data_frame.default.Rd +++ b/man/fortify_data_frame.default.Rd @@ -9,7 +9,7 @@ \arguments{ \item{data}{An object to be converted to a data frame.} -\item{...}{Arguments passed to methods.} +\item{...}{Additional arguments passed to \code{\link[ggplot2:fortify]{fortify()}}.} } \value{ A data frame. @@ -26,9 +26,7 @@ data frame. \seealso{ Other fortify_data_frame methods: \code{\link{fortify_data_frame.character}()}, -\code{\link{fortify_data_frame.complex}()}, -\code{\link{fortify_data_frame.logical}()}, -\code{\link{fortify_data_frame.matrix}()}, -\code{\link{fortify_data_frame.numeric}()} +\code{\link{fortify_data_frame.dendrogram}()}, +\code{\link{fortify_data_frame.matrix}()} } \concept{fortify_data_frame methods} diff --git a/man/dendrogram_data.Rd b/man/fortify_data_frame.dendrogram.Rd similarity index 54% rename from man/dendrogram_data.Rd rename to man/fortify_data_frame.dendrogram.Rd index 0be9fecb..6c7cef46 100644 --- a/man/dendrogram_data.Rd +++ b/man/fortify_data_frame.dendrogram.Rd @@ -1,11 +1,13 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/dendrogram.R -\name{dendrogram_data} -\alias{dendrogram_data} -\title{Dengrogram x and y coordinates} +\name{fortify_data_frame.dendrogram} +\alias{fortify_data_frame.dendrogram} +\alias{fortify_data_frame.hclust} +\title{Build a data frame} \usage{ -dendrogram_data( - tree, +\method{fortify_data_frame}{dendrogram}( + data, + ..., priority = "right", center = FALSE, type = "rectangle", @@ -16,10 +18,14 @@ dendrogram_data( root = NULL, double = TRUE ) + +\method{fortify_data_frame}{hclust}(data, ...) } \arguments{ -\item{tree}{A \link[stats:hclust]{hclust} or a \link[stats:dendrogram]{dendrogram} -object.} +\item{data}{A \code{\link[stats:hclust]{hclust}} or a +\code{\link[stats:dendrogram]{dendrogram}} object.} + +\item{...}{Additional arguments passed to \code{dendrogram} method.} \item{priority}{A string of "left" or "right". if we draw from right to left, the left will override the right, so we take the \code{"left"} as the priority. If @@ -53,34 +59,52 @@ horizontal lines will be repeated for each branch that the segment spans. If \code{FALSE}, only one horizontal line will be drawn.} } \value{ -A list of 2 data.frame. One for node coordinates, another for edge -coordinates. -\code{node} and tree segments \code{edge} coordinates contains following columns: +A \verb{data frame} with the node coordinates: \itemize{ -\item \code{index}: the original index in the tree for the current node +\item \code{.panel}: Similar with \code{panel} column, but always give the correct +branch for usage of the ggplot facet. +\item \code{.index}: the original index in the tree for the the node \item \code{label}: node label text -\item \code{x} and \code{y}: x-axis and y-axis coordinates for current node or the start -node of the current edge. -\item \code{xend} and \code{yend}: the x-axis and y-axis coordinates of the terminal node -for current edge. -\item \code{branch}: which branch current node or edge is. You can use this column -to color different groups. -\item \code{panel}: which panel current node is, if we split the plot into panel +\item \code{x} and \code{y}: x-axis and y-axis coordinates for the node +\item \code{branch}: which branch the node is. You can use this column to color +different groups. +\item \code{panel}: which panel the node is, if we split the plot into panel using \link[ggplot2:facet_grid]{facet_grid}, this column will show -which panel current node or edge is from. Note: some nodes may +which panel the node is from. Note: some nodes may fall outside panel (between two panels), so there are possible \code{NA} values in this column. -\item \code{ggpanel}: Similar with \code{panel} column, but always give the correct +\item \code{leaf}: A logical value indicates whether the node is a leaf. +} +} +\description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} + +This function converts various objects to a data frame. +} +\section{ggalign attributes}{ + +\code{edge}: A \verb{data frame} for edge coordinates: +\itemize{ +\item \code{.panel}: Similar with \code{panel} column, but always give the correct branch for usage of the ggplot facet. -\item \code{panel1} and \code{panel2}: The panel1 and panel2 variables have the same +\item \code{x} and \code{y}: x-axis and y-axis coordinates for the start node of the edge. +\item \code{xend} and \code{yend}: the x-axis and y-axis coordinates of the terminal node +for edge. +\item \code{branch}: which branch the edge is. You can use this column to color +different groups. +\item \code{panel1} and \code{panel2}: The panel1 and panel2 columns have the same functionality as \code{panel}, but they are specifically for the \code{edge} data and correspond to both nodes of each edge. -\item \code{leaf}: A logical value indicates whether current node is a leaf. } } -\description{ -Dengrogram x and y coordinates -} + \examples{ -dendrogram_data(hclust(dist(USArrests), "ave")) +fortify_data_frame(hclust(dist(USArrests), "ave")) +} +\seealso{ +Other fortify_data_frame methods: +\code{\link{fortify_data_frame.character}()}, +\code{\link{fortify_data_frame.default}()}, +\code{\link{fortify_data_frame.matrix}()} } +\concept{fortify_data_frame methods} diff --git a/man/fortify_data_frame.logical.Rd b/man/fortify_data_frame.logical.Rd deleted file mode 100644 index 9387c21d..00000000 --- a/man/fortify_data_frame.logical.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/fortify-data-frame.R -\name{fortify_data_frame.logical} -\alias{fortify_data_frame.logical} -\title{Build a data frame} -\usage{ -\method{fortify_data_frame}{logical}(data, ...) -} -\arguments{ -\item{data}{An object to be converted to a data frame.} - -\item{...}{Arguments passed to methods.} -} -\value{ -A data frame. -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - -This function converts various objects to a data frame. -} -\details{ -When \code{data} is an atomic vector, it'll be converted to a data frame with -following columns: -\itemize{ -\item \code{.names}: the names for the vector (only applicable if names exist). -\item \code{value}: the actual value of the vector. -} -} -\seealso{ -Other fortify_data_frame methods: -\code{\link{fortify_data_frame.character}()}, -\code{\link{fortify_data_frame.complex}()}, -\code{\link{fortify_data_frame.default}()}, -\code{\link{fortify_data_frame.matrix}()}, -\code{\link{fortify_data_frame.numeric}()} -} -\concept{fortify_data_frame methods} diff --git a/man/fortify_data_frame.matrix.Rd b/man/fortify_data_frame.matrix.Rd index 2668e648..b5e4a6bf 100644 --- a/man/fortify_data_frame.matrix.Rd +++ b/man/fortify_data_frame.matrix.Rd @@ -13,19 +13,11 @@ \method{fortify_data_frame}{Matrix}(data, ...) } \arguments{ -\item{data}{An object to be converted to a data frame.} +\item{data}{A matrix-like object.} -\item{...}{Arguments passed to methods.} +\item{...}{These dots are for future extensions and must be empty.} } \value{ -A data frame. -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - -This function converts various objects to a data frame. -} -\details{ Matrix will be transformed into a long-form data frame, where each row represents a unique combination of matrix indices and their corresponding values. The resulting data frame will contain the following columns: @@ -37,12 +29,15 @@ when names exist) and column index of the original matrix. \item \code{value}: the actual value. } } +\description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} + +This function converts various objects to a data frame. +} \seealso{ Other fortify_data_frame methods: \code{\link{fortify_data_frame.character}()}, -\code{\link{fortify_data_frame.complex}()}, \code{\link{fortify_data_frame.default}()}, -\code{\link{fortify_data_frame.logical}()}, -\code{\link{fortify_data_frame.numeric}()} +\code{\link{fortify_data_frame.dendrogram}()} } \concept{fortify_data_frame methods} diff --git a/man/fortify_data_frame.numeric.Rd b/man/fortify_data_frame.numeric.Rd deleted file mode 100644 index 462d225e..00000000 --- a/man/fortify_data_frame.numeric.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/fortify-data-frame.R -\name{fortify_data_frame.numeric} -\alias{fortify_data_frame.numeric} -\title{Build a data frame} -\usage{ -\method{fortify_data_frame}{numeric}(data, ...) -} -\arguments{ -\item{data}{An object to be converted to a data frame.} - -\item{...}{Arguments passed to methods.} -} -\value{ -A data frame. -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - -This function converts various objects to a data frame. -} -\details{ -When \code{data} is an atomic vector, it'll be converted to a data frame with -following columns: -\itemize{ -\item \code{.names}: the names for the vector (only applicable if names exist). -\item \code{value}: the actual value of the vector. -} -} -\seealso{ -Other fortify_data_frame methods: -\code{\link{fortify_data_frame.character}()}, -\code{\link{fortify_data_frame.complex}()}, -\code{\link{fortify_data_frame.default}()}, -\code{\link{fortify_data_frame.logical}()}, -\code{\link{fortify_data_frame.matrix}()} -} -\concept{fortify_data_frame methods} diff --git a/man/fortify_data_frame.phylo.Rd b/man/fortify_data_frame.phylo.Rd index 70990d14..f666cba5 100644 --- a/man/fortify_data_frame.phylo.Rd +++ b/man/fortify_data_frame.phylo.Rd @@ -14,9 +14,10 @@ ) } \arguments{ -\item{data}{An object to be converted to a data frame.} +\item{data}{A \code{\link[stats:hclust]{hclust}} or a +\code{\link[stats:dendrogram]{dendrogram}} object.} -\item{...}{Arguments passed to methods.} +\item{...}{These dots are for future extensions and must be empty.} \item{type}{A string indicates the plot type, \code{"rectangle"} or \code{"triangle"}.} @@ -32,14 +33,6 @@ Usually, you don't need to modify this.} of the number of tips in \code{tree}.} } \value{ -A data frame. -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} - -This function converts various objects to a data frame. -} -\details{ A \verb{data frame} with the node coordinates: \itemize{ \item \code{.index}: the original index in the tree for the the tip/node. @@ -48,6 +41,11 @@ A \verb{data frame} with the node coordinates: \item \code{tip}: A logical value indicates whether current node is a tip. } } +\description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} + +This function converts various objects to a data frame. +} \section{ggalign attributes}{ \code{edge}: A \verb{data frame} for edge coordinates: @@ -58,11 +56,3 @@ for edge. } } -\seealso{ -Other fortify_data_frame methods: -\code{\link{fortify_data_frame.character}()}, -\code{\link{fortify_data_frame.complex}()}, -\code{\link{fortify_data_frame.logical}()}, -\code{\link{fortify_data_frame.matrix}()}, -\code{\link{fortify_data_frame.numeric}()} -} diff --git a/man/fortify_matrix.GISTIC.Rd b/man/fortify_matrix.GISTIC.Rd index 94a16895..eedf228b 100644 --- a/man/fortify_matrix.GISTIC.Rd +++ b/man/fortify_matrix.GISTIC.Rd @@ -15,9 +15,9 @@ ) } \arguments{ -\item{data}{An object to be converted to a matrix.} +\item{data}{A \code{\link[maftools:readGistic]{GISTIC}} object.} -\item{...}{Not used currently.} +\item{...}{These dots are for future extensions and must be empty.} \item{n_top}{A single number indicates how many top bands to be drawn.} diff --git a/man/fortify_matrix.MAF.Rd b/man/fortify_matrix.MAF.Rd index 38038a3e..de84eff8 100644 --- a/man/fortify_matrix.MAF.Rd +++ b/man/fortify_matrix.MAF.Rd @@ -15,9 +15,9 @@ ) } \arguments{ -\item{data}{An object to be converted to a matrix.} +\item{data}{A \code{\link[maftools:read.maf]{MAF}} object.} -\item{...}{Not used currently.} +\item{...}{These dots are for future extensions and must be empty.} \item{genes}{An atomic character defines the genes to draw.} diff --git a/man/fortify_matrix.default.Rd b/man/fortify_matrix.default.Rd index 9a2ce110..7424b2d1 100644 --- a/man/fortify_matrix.default.Rd +++ b/man/fortify_matrix.default.Rd @@ -15,6 +15,11 @@ A matrix. } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} + +This function converts various objects into a matrix format. +} +\details{ By default, it calls \code{\link[=as.matrix]{as.matrix()}} to build a matrix. } \seealso{