From ad94452f1e55ddd1477d9c3ae87fb1e75455aea3 Mon Sep 17 00:00:00 2001 From: yun Date: Thu, 11 Jul 2024 22:08:38 +0800 Subject: [PATCH] eanno: collapse width and height into size argument --- R/anno-gg.R | 28 +++++++++++------------ R/eanno.R | 55 ++++++++++++++++++++++++--------------------- R/eheat_anno.R | 9 ++++---- R/gganno.R | 7 +++--- README.html | 32 +++++++++++++------------- README.md | 32 +++++++++++++------------- man/anno_gg.Rd | 41 ++++++++++++++++++++------------- man/eanno.Rd | 32 +++++++++++++++++--------- man/eheat_anno.Rd | 7 +++--- man/gganno.Rd | 23 ++++++++++++++----- vignettes/eheat.Rmd | 32 +++++++++++++------------- 11 files changed, 165 insertions(+), 133 deletions(-) diff --git a/R/anno-gg.R b/R/anno-gg.R index 2aa4014..126b2d3 100644 --- a/R/anno-gg.R +++ b/R/anno-gg.R @@ -13,7 +13,7 @@ #' top_annotation = eheat_anno( #' ggplot = anno_gg(g, "panel", #' clip = "off", -#' height = unit(6, "cm"), +#' size = unit(6, "cm"), #' show_name = FALSE #' ) #' ) @@ -24,7 +24,7 @@ #' top_annotation = eheat_anno( #' ggplot = anno_gg(g, "panel", #' clip = "on", -#' height = unit(6, "cm"), +#' size = unit(6, "cm"), #' show_name = FALSE #' ) #' ) @@ -34,7 +34,7 @@ #' ggheat(m, #' top_annotation = eheat_anno( #' ggplot = anno_gg(g, "plot", -#' height = unit(6, "cm"), +#' size = unit(6, "cm"), #' show_name = FALSE #' ) #' ) @@ -44,15 +44,14 @@ #' ggheat(m, #' top_annotation = eheat_anno( #' ggplot = anno_gg(g, "full", -#' height = unit(6, "cm"), +#' size = unit(6, "cm"), #' show_name = FALSE #' ) #' ) #' ) #' @export anno_gg <- function(gg, align_with = "full", clip = NULL, gt = NULL, - width = NULL, height = NULL, show_name = FALSE, - which = NULL) { + size = NULL, show_name = FALSE, which = NULL) { if (is.null(gt)) { assert_s3_class(gg, "ggplot") gt <- ggplot2::ggplotGrob(gg) @@ -67,7 +66,7 @@ anno_gg <- function(gg, align_with = "full", clip = NULL, gt = NULL, margins <- setup_margins(clip, vp) .ggfit(gt, align_with, margins) }, - which = which, width = width, height = height, + which = which, size = size, show_name = show_name, fun_name = "anno_gg" ) } @@ -78,7 +77,7 @@ anno_gg <- function(gg, align_with = "full", clip = NULL, gt = NULL, #' top_annotation = eheat_anno( #' ggplot = anno_gg2(g, "panel", #' margins = NULL, -#' height = unit(6, "cm"), +#' size = unit(6, "cm"), #' show_name = FALSE #' ) #' ) @@ -89,7 +88,7 @@ anno_gg <- function(gg, align_with = "full", clip = NULL, gt = NULL, #' top_annotation = eheat_anno( #' ggplot = anno_gg2(g, "panel", #' margins = "l", -#' height = unit(6, "cm"), +#' size = unit(6, "cm"), #' show_name = FALSE #' ) #' ) @@ -100,7 +99,7 @@ anno_gg <- function(gg, align_with = "full", clip = NULL, gt = NULL, #' top_annotation = eheat_anno( #' ggplot = anno_gg2(g, "panel", #' margins = "r", -#' height = unit(6, "cm"), +#' size = unit(6, "cm"), #' show_name = FALSE #' ) #' ) @@ -110,7 +109,7 @@ anno_gg <- function(gg, align_with = "full", clip = NULL, gt = NULL, #' ggheat(m, #' top_annotation = eheat_anno( #' ggplot = anno_gg2(g, "plot", -#' height = unit(6, "cm"), +#' size = unit(6, "cm"), #' show_name = FALSE #' ) #' ) @@ -120,7 +119,7 @@ anno_gg <- function(gg, align_with = "full", clip = NULL, gt = NULL, #' ggheat(m, #' top_annotation = eheat_anno( #' ggplot = anno_gg2(g, "full", -#' height = unit(6, "cm"), +#' size = unit(6, "cm"), #' show_name = FALSE #' ) #' ) @@ -133,8 +132,7 @@ anno_gg2 <- function(gg, align_with = "full", "axis", "lab", "guide", "subtitle", "title", "caption" ), - gt = NULL, - width = NULL, height = NULL, show_name = FALSE, + gt = NULL, size = NULL, show_name = FALSE, which = NULL) { if (is.null(gt)) { assert_s3_class(gg, "ggplot") @@ -150,7 +148,7 @@ anno_gg2 <- function(gg, align_with = "full", function(index, k, n) { .ggfit(gt, align_with, margins, elements) }, - which = which, width = width, height = height, + which = which, size = size, show_name = show_name, fun_name = "anno_gg2" ) } diff --git a/R/eanno.R b/R/eanno.R index f13de94..169feef 100644 --- a/R/eanno.R +++ b/R/eanno.R @@ -25,6 +25,20 @@ #' @param data A `matrix` or `data.frame`, if it is a simple vector, it will be #' converted to a one-column matrix. If `NULL`, the matrix from the heatmap will #' be used. You can also provide a function to transform the matrix. +#' @param size The `width/height` of the plotting region (the viewport) that the +#' annotation is drawn. If it is a `row` annotation, `size` is regarded as the +#' `width`, otherwise, the `height`. `size` must be an absolute +#' [unit][grid::unit] object. Since the +#' [AnnotationFunction][ComplexHeatmap::AnnotationFunction-class] object is +#' always contained by the +#' [SingleAnnotation-class][ComplexHeatmap::SingleAnnotation-class] object, you +#' can only set the `width` of row annotations or `height` of column +#' annotations, while e.g. the `height` of the row annotation and `width` of the +#' column annotations is always `unit(1, "npc")` which means it always fully +#' filled in the parent `SingleAnnotation` and only in +#' [SingleAnnotation][ComplexHeatmap::SingleAnnotation] or even +#' [HeatmapAnnotation][ComplexHeatmap::HeatmapAnnotation] can adjust the +#' `height` of the row annotations or `width` of the column annotations. #' @inheritParams ComplexHeatmap::AnnotationFunction #' @param subset_rule A list of function to subset variables in `...`. #' @param fun_name Name of the annotation function, only used for message. @@ -54,7 +68,7 @@ #' if (k == 1) grid.yaxis() #' popViewport() #' }, -#' height = unit(2, "cm") +#' size = unit(2, "cm") #' ) #' m <- rbind(1:10, 11:20) #' eheat(m, top_annotation = eheat_anno(foo = anno)) @@ -70,15 +84,16 @@ #' popViewport() #' }, #' data = rnorm(10L), subset_rule = TRUE, -#' height = unit(2, "cm") +#' size = unit(2, "cm") #' ) #' draw(anno) #' draw(anno[1:2]) #' @seealso [AnnotationFunction][ComplexHeatmap::AnnotationFunction] #' @return A `ExtendedAnnotation` object. #' @export -eanno <- function(draw_fn, ..., data = NULL, which = NULL, subset_rule = NULL, - width = NULL, height = NULL, show_name = TRUE, +eanno <- function(draw_fn, ..., data = NULL, + size = NULL, show_name = TRUE, which = NULL, + subset_rule = NULL, legends_margin = NULL, legends_panel = NULL, fun_name = NULL) { if (ht_opt$verbose) { @@ -149,9 +164,9 @@ eanno <- function(draw_fn, ..., data = NULL, which = NULL, subset_rule = NULL, anno@which <- which anno@fun <- unclass(draw_fn) anno@fun_name <- fun_name %||% "eanno" - anno_size <- anno_width_and_height(which, width, height, unit(1, "cm")) - anno@width <- anno_size$width - anno@height <- anno_size$height + anno_size <- anno_width_and_height(which, size, unit(1, "cm")) + anno@width <- .subset2(anno_size, "width") + anno@height <- .subset2(anno_size, "height") anno@show_name <- show_name anno@n <- n anno@data_scale <- c(0L, 1L) @@ -466,27 +481,15 @@ methods::setMethod( } ) -anno_width_and_height <- function(which, width = NULL, height = NULL, +anno_width_and_height <- function(which, size = NULL, default = unit(10, "mm")) { - params <- list(width = width, height = height) + size <- size %||% default + if (!ComplexHeatmap::is_abs_unit(size)) { + cli::cli_abort("{.arg size} must be an absolute unit.", ) + } if (which == "row") { - # we flip the width and height in this way, both row and column - # annotation, height must be absolute unit - params <- flip_gp(params) - arg <- "width" # nolint + list(width = size, height = unit(1L, "npc")) } else { - arg <- "height" - } - if (is.null(.subset2(params, "height"))) { - params$height <- default - } else if (!ComplexHeatmap::is_abs_unit(.subset2(params, "height"))) { - cli::cli_abort(paste( - "{.arg {arg}} of the {.field {which}} annotation", - "must be an absolute unit." - )) - } - if (is.null(.subset2(params, "width"))) { - params$width <- unit(1L, "npc") + list(width = unit(1L, "npc"), height = size) } - if (which == "row") flip_gp(params) else params } diff --git a/R/eheat_anno.R b/R/eheat_anno.R index dd44ae0..36468b9 100644 --- a/R/eheat_anno.R +++ b/R/eheat_anno.R @@ -10,14 +10,15 @@ #' #' @param ... Additional arguments passed to #' [HeatmapAnnotation][ComplexHeatmap::HeatmapAnnotation]. -#' @param annotation_size Height/width of each annotation for column/row +#' @param annotation_size `Height/width` of each annotation for column/row +#' annotation. +#' @param size `Height/width` of the whole annotations for column/row #' annotation. -#' @param size Height/width of the whole annotations for column/row annotation. #' @param which A string of `"row"` or `"column"`. #' @return A [HeatmapAnnotation][ComplexHeatmap::HeatmapAnnotation-class] #' object. #' @examples -#' # No need to specify which argument if combine with `ggheat` or `eheat` +#' # No need to specify `which` argument if combined with `ggheat` or `eheat` #' g <- ggplot(mpg, aes(displ, hwy, colour = class)) + #' geom_point() #' m <- matrix(rnorm(100), 10) @@ -25,7 +26,7 @@ #' top_annotation = eheat_anno( #' ggplot = anno_gg(g, "panel", #' clip = "on", -#' height = unit(6, "cm"), +#' size = unit(6, "cm"), #' show_name = FALSE #' ) #' ) diff --git a/R/gganno.R b/R/gganno.R index e912232..1b52f6d 100644 --- a/R/gganno.R +++ b/R/gganno.R @@ -34,16 +34,15 @@ #' @examples #' draw(gganno(function(p) { #' p + geom_point(aes(y = value)) -#' }, data = rnorm(10L), height = unit(10, "cm"), width = unit(0.7, "npc"))) +#' }, data = rnorm(10L), size = unit(10, "cm"))) #' @return A `ggAnno` object. #' @export #' @name gganno -gganno <- function(ggfn, ..., data = NULL, - which = NULL, width = NULL, height = NULL) { +gganno <- function(ggfn, ..., data = NULL, size = NULL, which = NULL) { if (missing(ggfn)) ggfn <- ~.x out <- eanno( draw_fn = ggfn, ..., data = data, subset_rule = NULL, - which = which, width = width, height = height, + size = size, which = which, show_name = FALSE, fun_name = "gganno", legends_margin = NULL, legends_panel = NULL ) diff --git a/README.html b/README.html index 3b8934f..1e00f5b 100644 --- a/README.html +++ b/README.html @@ -1153,7 +1153,7 @@

gganno

data = anno_data, function(p) { p + geom_bar(aes(y = value, fill = factor(.row_index)), stat = "identity") - }, height = unit(5, "cm") + }, size = unit(5, "cm") ) ) ), merge_legends = TRUE) @@ -1166,7 +1166,7 @@

gganno

data = anno_data, function(p) { p + geom_boxplot(aes(y = value, fill = factor(.slice))) - }, height = unit(5, "cm") + }, size = unit(5, "cm") ) ), column_km = 2L ), merge_legends = TRUE) @@ -1205,7 +1205,7 @@

gganno

scale_color_brewer( name = "Slice", type = "qual", palette = "Set1" ) - }, height = unit(3, "cm") + }, size = unit(3, "cm") ) ), column_km = 2L ), merge_legends = TRUE) @@ -1217,7 +1217,7 @@

gganno

data = anno_data, function(p) { p + aes(y = value) + geom_text(aes(label = .row_index)) - }, height = unit(2, "cm") + }, size = unit(2, "cm") ) ), bottom_annotation = eheat_anno( @@ -1228,7 +1228,7 @@

gganno

scale_y_reverse() }, data = anno_data, - height = unit(2, "cm") + size = unit(2, "cm") ) ), right_annotation = eheat_anno( @@ -1238,7 +1238,7 @@

gganno

geom_text(aes(label = .row_index)) }, data = anno_data, - width = unit(3, "cm") + size = unit(3, "cm") ) ), left_annotation = eheat_anno( @@ -1249,7 +1249,7 @@

gganno

scale_x_reverse() }, data = anno_data, - width = unit(3, "cm") + size = unit(3, "cm") ) ), row_km = 2L, column_km = 2L, @@ -1290,7 +1290,7 @@

anno_gg and top_annotation = eheat_anno( ggplot = anno_gg(g, "panel", clip = "off", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -1302,7 +1302,7 @@

anno_gg and top_annotation = eheat_anno( ggplot = anno_gg(g, "panel", clip = "on", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -1313,7 +1313,7 @@

anno_gg and ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg(g, "plot", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -1325,7 +1325,7 @@

anno_gg and ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg(g, "full", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -1340,7 +1340,7 @@

anno_gg and top_annotation = eheat_anno( ggplot = anno_gg2(g, "panel", margins = NULL, - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -1352,7 +1352,7 @@

anno_gg and top_annotation = eheat_anno( ggplot = anno_gg2(g, "panel", margins = "l", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -1364,7 +1364,7 @@

anno_gg and top_annotation = eheat_anno( ggplot = anno_gg2(g, "panel", margins = "r", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -1375,7 +1375,7 @@

anno_gg and ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg2(g, "plot", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -1397,7 +1397,7 @@

anno_gg and ncol = 2L )), align_with = "full", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) diff --git a/README.md b/README.md index dbd7929..e2dde9e 100644 --- a/README.md +++ b/README.md @@ -681,7 +681,7 @@ draw(ggheat(small_mat, data = anno_data, function(p) { p + geom_bar(aes(y = value, fill = factor(.row_index)), stat = "identity") - }, height = unit(5, "cm") + }, size = unit(5, "cm") ) ) ), merge_legends = TRUE) @@ -697,7 +697,7 @@ draw(ggheat(small_mat, data = anno_data, function(p) { p + geom_boxplot(aes(y = value, fill = factor(.slice))) - }, height = unit(5, "cm") + }, size = unit(5, "cm") ) ), column_km = 2L ), merge_legends = TRUE) @@ -739,7 +739,7 @@ draw(ggheat(small_mat, scale_color_brewer( name = "Slice", type = "qual", palette = "Set1" ) - }, height = unit(3, "cm") + }, size = unit(3, "cm") ) ), column_km = 2L ), merge_legends = TRUE) @@ -754,7 +754,7 @@ draw(ggheat(small_mat, data = anno_data, function(p) { p + aes(y = value) + geom_text(aes(label = .row_index)) - }, height = unit(2, "cm") + }, size = unit(2, "cm") ) ), bottom_annotation = eheat_anno( @@ -765,7 +765,7 @@ draw(ggheat(small_mat, scale_y_reverse() }, data = anno_data, - height = unit(2, "cm") + size = unit(2, "cm") ) ), right_annotation = eheat_anno( @@ -775,7 +775,7 @@ draw(ggheat(small_mat, geom_text(aes(label = .row_index)) }, data = anno_data, - width = unit(3, "cm") + size = unit(3, "cm") ) ), left_annotation = eheat_anno( @@ -786,7 +786,7 @@ draw(ggheat(small_mat, scale_x_reverse() }, data = anno_data, - width = unit(3, "cm") + size = unit(3, "cm") ) ), row_km = 2L, column_km = 2L, @@ -834,7 +834,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg(g, "panel", clip = "off", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -849,7 +849,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg(g, "panel", clip = "on", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -863,7 +863,7 @@ ggheat(m, ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg(g, "plot", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -878,7 +878,7 @@ ggheat(m, ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg(g, "full", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -896,7 +896,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg2(g, "panel", margins = NULL, - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -911,7 +911,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg2(g, "panel", margins = "l", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -926,7 +926,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg2(g, "panel", margins = "r", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -940,7 +940,7 @@ ggheat(m, ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg2(g, "plot", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -965,7 +965,7 @@ ggheat(m, ncol = 2L )), align_with = "full", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) diff --git a/man/anno_gg.Rd b/man/anno_gg.Rd index 6440846..a4667f5 100644 --- a/man/anno_gg.Rd +++ b/man/anno_gg.Rd @@ -10,8 +10,7 @@ anno_gg( align_with = "full", clip = NULL, gt = NULL, - width = NULL, - height = NULL, + size = NULL, show_name = FALSE, which = NULL ) @@ -22,8 +21,7 @@ anno_gg2( margins = c("b", "t", "l", "r"), elements = c("axis", "lab", "guide", "subtitle", "title", "caption"), gt = NULL, - width = NULL, - height = NULL, + size = NULL, show_name = FALSE, which = NULL ) @@ -41,9 +39,20 @@ to \code{"on"} and \code{FALSE} corresponds to \code{"off"}. Default: \code{"inh \item{gt}{A \link[ggplot2:ggplotGrob]{gtable} object.} -\item{width}{The width of the plotting region (the viewport) that the annotation is drawn. If it is a row annotation, the width must be an absolute unit. Since the \code{AnnotationFunction} object is always contained by the \code{\link[ComplexHeatmap]{SingleAnnotation-class}}object, you can only set the width of row annotations or height of column annotations, while e.g. the height of the row annotation is always \code{unit(1, "npc")} which means it always fully filled in the parent \code{SingleAnnotation} and only in \code{\link[ComplexHeatmap]{SingleAnnotation}} or even \code{\link[ComplexHeatmap]{HeatmapAnnotation}} can adjust the height of the row annotations.} - -\item{height}{The height of the plotting region (the viewport) that the annotation is drawn. If it is a column annotation, the width must be an absolute unit.} +\item{size}{The \code{width/height} of the plotting region (the viewport) that the +annotation is drawn. If it is a \code{row} annotation, \code{size} is regarded as the +\code{width}, otherwise, the \code{height}. \code{size} must be an absolute +\link[grid:unit]{unit} object. Since the +\link[ComplexHeatmap:AnnotationFunction-class]{AnnotationFunction} object is +always contained by the +\link[ComplexHeatmap:SingleAnnotation-class]{SingleAnnotation-class} object, you +can only set the \code{width} of row annotations or \code{height} of column +annotations, while e.g. the \code{height} of the row annotation and \code{width} of the +column annotations is always \code{unit(1, "npc")} which means it always fully +filled in the parent \code{SingleAnnotation} and only in +\link[ComplexHeatmap:SingleAnnotation]{SingleAnnotation} or even +\link[ComplexHeatmap:HeatmapAnnotation]{HeatmapAnnotation} can adjust the +\code{height} of the row annotations or \code{width} of the column annotations.} \item{show_name}{It is used to turn off the drawing of annotation names in \code{\link[ComplexHeatmap]{HeatmapAnnotation}}. Annotations always have names associated and normally they will be drawn beside the annotation graphics to tell what the annotation is about. e.g. the annotation names put beside the points annotation graphics. However, for some of the annotations, the names are not necessarily to be drawn, such as text annotations drawn by \code{\link[ComplexHeatmap]{anno_text}} or an empty annotation drawn by \code{\link[ComplexHeatmap]{anno_empty}}. In this case, when \code{show_names} is set to \code{FALSE}, there will be no annotation names drawn for the annotation.} @@ -75,7 +84,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg(g, "panel", clip = "off", - height = unit(6, "cm"), + size = unit(6, "cm"), show_name = FALSE ) ) @@ -86,7 +95,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg(g, "panel", clip = "on", - height = unit(6, "cm"), + size = unit(6, "cm"), show_name = FALSE ) ) @@ -96,7 +105,7 @@ ggheat(m, ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg(g, "plot", - height = unit(6, "cm"), + size = unit(6, "cm"), show_name = FALSE ) ) @@ -106,7 +115,7 @@ ggheat(m, ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg(g, "full", - height = unit(6, "cm"), + size = unit(6, "cm"), show_name = FALSE ) ) @@ -116,7 +125,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg2(g, "panel", margins = NULL, - height = unit(6, "cm"), + size = unit(6, "cm"), show_name = FALSE ) ) @@ -127,7 +136,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg2(g, "panel", margins = "l", - height = unit(6, "cm"), + size = unit(6, "cm"), show_name = FALSE ) ) @@ -138,7 +147,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg2(g, "panel", margins = "r", - height = unit(6, "cm"), + size = unit(6, "cm"), show_name = FALSE ) ) @@ -148,7 +157,7 @@ ggheat(m, ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg2(g, "plot", - height = unit(6, "cm"), + size = unit(6, "cm"), show_name = FALSE ) ) @@ -158,7 +167,7 @@ ggheat(m, ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg2(g, "full", - height = unit(6, "cm"), + size = unit(6, "cm"), show_name = FALSE ) ) diff --git a/man/eanno.Rd b/man/eanno.Rd index 09059e8..f46d4d5 100644 --- a/man/eanno.Rd +++ b/man/eanno.Rd @@ -10,11 +10,10 @@ eanno( draw_fn, ..., data = NULL, + size = NULL, + show_name = TRUE, which = NULL, subset_rule = NULL, - width = NULL, - height = NULL, - show_name = TRUE, legends_margin = NULL, legends_panel = NULL, fun_name = NULL @@ -48,15 +47,26 @@ can be subsettable.} converted to a one-column matrix. If \code{NULL}, the matrix from the heatmap will be used. You can also provide a function to transform the matrix.} -\item{which}{Whether it is drawn as a column annotation or a row annotation?} - -\item{subset_rule}{A list of function to subset variables in \code{...}.} +\item{size}{The \code{width/height} of the plotting region (the viewport) that the +annotation is drawn. If it is a \code{row} annotation, \code{size} is regarded as the +\code{width}, otherwise, the \code{height}. \code{size} must be an absolute +\link[grid:unit]{unit} object. Since the +\link[ComplexHeatmap:AnnotationFunction-class]{AnnotationFunction} object is +always contained by the +\link[ComplexHeatmap:SingleAnnotation-class]{SingleAnnotation-class} object, you +can only set the \code{width} of row annotations or \code{height} of column +annotations, while e.g. the \code{height} of the row annotation and \code{width} of the +column annotations is always \code{unit(1, "npc")} which means it always fully +filled in the parent \code{SingleAnnotation} and only in +\link[ComplexHeatmap:SingleAnnotation]{SingleAnnotation} or even +\link[ComplexHeatmap:HeatmapAnnotation]{HeatmapAnnotation} can adjust the +\code{height} of the row annotations or \code{width} of the column annotations.} -\item{width}{The width of the plotting region (the viewport) that the annotation is drawn. If it is a row annotation, the width must be an absolute unit. Since the \code{AnnotationFunction} object is always contained by the \code{\link[ComplexHeatmap]{SingleAnnotation-class}}object, you can only set the width of row annotations or height of column annotations, while e.g. the height of the row annotation is always \code{unit(1, "npc")} which means it always fully filled in the parent \code{SingleAnnotation} and only in \code{\link[ComplexHeatmap]{SingleAnnotation}} or even \code{\link[ComplexHeatmap]{HeatmapAnnotation}} can adjust the height of the row annotations.} +\item{show_name}{It is used to turn off the drawing of annotation names in \code{\link[ComplexHeatmap]{HeatmapAnnotation}}. Annotations always have names associated and normally they will be drawn beside the annotation graphics to tell what the annotation is about. e.g. the annotation names put beside the points annotation graphics. However, for some of the annotations, the names are not necessarily to be drawn, such as text annotations drawn by \code{\link[ComplexHeatmap]{anno_text}} or an empty annotation drawn by \code{\link[ComplexHeatmap]{anno_empty}}. In this case, when \code{show_names} is set to \code{FALSE}, there will be no annotation names drawn for the annotation.} -\item{height}{The height of the plotting region (the viewport) that the annotation is drawn. If it is a column annotation, the width must be an absolute unit.} +\item{which}{Whether it is drawn as a column annotation or a row annotation?} -\item{show_name}{It is used to turn off the drawing of annotation names in \code{\link[ComplexHeatmap]{HeatmapAnnotation}}. Annotations always have names associated and normally they will be drawn beside the annotation graphics to tell what the annotation is about. e.g. the annotation names put beside the points annotation graphics. However, for some of the annotations, the names are not necessarily to be drawn, such as text annotations drawn by \code{\link[ComplexHeatmap]{anno_text}} or an empty annotation drawn by \code{\link[ComplexHeatmap]{anno_empty}}. In this case, when \code{show_names} is set to \code{FALSE}, there will be no annotation names drawn for the annotation.} +\item{subset_rule}{A list of function to subset variables in \code{...}.} \item{legends_margin, legends_panel}{A list of \link[ComplexHeatmap:Legends-class]{Legends} objects. \code{legends_margin} will be @@ -94,7 +104,7 @@ anno <- eanno( if (k == 1) grid.yaxis() popViewport() }, - height = unit(2, "cm") + size = unit(2, "cm") ) m <- rbind(1:10, 11:20) eheat(m, top_annotation = eheat_anno(foo = anno)) @@ -110,7 +120,7 @@ anno <- eanno( popViewport() }, data = rnorm(10L), subset_rule = TRUE, - height = unit(2, "cm") + size = unit(2, "cm") ) draw(anno) draw(anno[1:2]) diff --git a/man/eheat_anno.Rd b/man/eheat_anno.Rd index 9e9ac7f..eaf59c8 100644 --- a/man/eheat_anno.Rd +++ b/man/eheat_anno.Rd @@ -10,10 +10,11 @@ eheat_anno(..., annotation_size = NULL, size = NULL, which = NULL) \item{...}{Additional arguments passed to \link[ComplexHeatmap:HeatmapAnnotation]{HeatmapAnnotation}.} -\item{annotation_size}{Height/width of each annotation for column/row +\item{annotation_size}{\code{Height/width} of each annotation for column/row annotation.} -\item{size}{Height/width of the whole annotations for column/row annotation.} +\item{size}{\code{Height/width} of the whole annotations for column/row +annotation.} \item{which}{A string of \code{"row"} or \code{"column"}.} } @@ -39,7 +40,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg(g, "panel", clip = "on", - height = unit(6, "cm"), + size = unit(6, "cm"), show_name = FALSE ) ) diff --git a/man/gganno.Rd b/man/gganno.Rd index 8018747..c2d034e 100644 --- a/man/gganno.Rd +++ b/man/gganno.Rd @@ -6,7 +6,7 @@ \alias{ggAnno-class} \title{Build ggAnno Class} \usage{ -gganno(ggfn, ..., data = NULL, which = NULL, width = NULL, height = NULL) +gganno(ggfn, ..., data = NULL, size = NULL, which = NULL) } \arguments{ \item{ggfn}{A function or formula, accept a initial \link[ggplot2:ggplot]{ggplot} @@ -26,11 +26,22 @@ very compact anonymous functions (lambdas) with up to two inputs.} converted to a one-column matrix. If \code{NULL}, the matrix from the heatmap will be used. You can also provide a function to transform the matrix.} -\item{which}{Whether it is drawn as a column annotation or a row annotation?} - -\item{width}{The width of the plotting region (the viewport) that the annotation is drawn. If it is a row annotation, the width must be an absolute unit. Since the \code{AnnotationFunction} object is always contained by the \code{\link[ComplexHeatmap]{SingleAnnotation-class}}object, you can only set the width of row annotations or height of column annotations, while e.g. the height of the row annotation is always \code{unit(1, "npc")} which means it always fully filled in the parent \code{SingleAnnotation} and only in \code{\link[ComplexHeatmap]{SingleAnnotation}} or even \code{\link[ComplexHeatmap]{HeatmapAnnotation}} can adjust the height of the row annotations.} +\item{size}{The \code{width/height} of the plotting region (the viewport) that the +annotation is drawn. If it is a \code{row} annotation, \code{size} is regarded as the +\code{width}, otherwise, the \code{height}. \code{size} must be an absolute +\link[grid:unit]{unit} object. Since the +\link[ComplexHeatmap:AnnotationFunction-class]{AnnotationFunction} object is +always contained by the +\link[ComplexHeatmap:SingleAnnotation-class]{SingleAnnotation-class} object, you +can only set the \code{width} of row annotations or \code{height} of column +annotations, while e.g. the \code{height} of the row annotation and \code{width} of the +column annotations is always \code{unit(1, "npc")} which means it always fully +filled in the parent \code{SingleAnnotation} and only in +\link[ComplexHeatmap:SingleAnnotation]{SingleAnnotation} or even +\link[ComplexHeatmap:HeatmapAnnotation]{HeatmapAnnotation} can adjust the +\code{height} of the row annotations or \code{width} of the column annotations.} -\item{height}{The height of the plotting region (the viewport) that the annotation is drawn. If it is a column annotation, the width must be an absolute unit.} +\item{which}{Whether it is drawn as a column annotation or a row annotation?} } \value{ A \code{ggAnno} object. @@ -73,7 +84,7 @@ internal operations. \examples{ draw(gganno(function(p) { p + geom_point(aes(y = value)) -}, data = rnorm(10L), height = unit(10, "cm"), width = unit(0.7, "npc"))) +}, data = rnorm(10L), size = unit(10, "cm"))) } \seealso{ \link{eanno} diff --git a/vignettes/eheat.Rmd b/vignettes/eheat.Rmd index 39b23fd..3451408 100644 --- a/vignettes/eheat.Rmd +++ b/vignettes/eheat.Rmd @@ -482,7 +482,7 @@ draw(ggheat(small_mat, data = anno_data, function(p) { p + geom_bar(aes(y = value, fill = factor(.row_index)), stat = "identity") - }, height = unit(5, "cm") + }, size = unit(5, "cm") ) ) ), merge_legends = TRUE) @@ -495,7 +495,7 @@ draw(ggheat(small_mat, data = anno_data, function(p) { p + geom_boxplot(aes(y = value, fill = factor(.slice))) - }, height = unit(5, "cm") + }, size = unit(5, "cm") ) ), column_km = 2L ), merge_legends = TRUE) @@ -534,7 +534,7 @@ draw(ggheat(small_mat, scale_color_brewer( name = "Slice", type = "qual", palette = "Set1" ) - }, height = unit(3, "cm") + }, size = unit(3, "cm") ) ), column_km = 2L ), merge_legends = TRUE) @@ -547,7 +547,7 @@ draw(ggheat(small_mat, data = anno_data, function(p) { p + aes(y = value) + geom_text(aes(label = .row_index)) - }, height = unit(2, "cm") + }, size = unit(2, "cm") ) ), bottom_annotation = eheat_anno( @@ -558,7 +558,7 @@ draw(ggheat(small_mat, scale_y_reverse() }, data = anno_data, - height = unit(2, "cm") + size = unit(2, "cm") ) ), right_annotation = eheat_anno( @@ -568,7 +568,7 @@ draw(ggheat(small_mat, geom_text(aes(label = .row_index)) }, data = anno_data, - width = unit(3, "cm") + size = unit(3, "cm") ) ), left_annotation = eheat_anno( @@ -579,7 +579,7 @@ draw(ggheat(small_mat, scale_x_reverse() }, data = anno_data, - width = unit(3, "cm") + size = unit(3, "cm") ) ), row_km = 2L, column_km = 2L, @@ -615,7 +615,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg(g, "panel", clip = "off", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -628,7 +628,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg(g, "panel", clip = "on", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -640,7 +640,7 @@ ggheat(m, ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg(g, "plot", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -650,7 +650,7 @@ ggheat(m, ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg(g, "full", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -665,7 +665,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg2(g, "panel", margins = NULL, - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -678,7 +678,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg2(g, "panel", margins = "l", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -691,7 +691,7 @@ ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg2(g, "panel", margins = "r", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -703,7 +703,7 @@ ggheat(m, ggheat(m, top_annotation = eheat_anno( ggplot = anno_gg2(g, "plot", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) ) @@ -726,7 +726,7 @@ ggheat(m, ncol = 2L )), align_with = "full", - height = unit(3, "cm"), + size = unit(3, "cm"), show_name = FALSE ) )