diff --git a/R/anno-gg.R b/R/anno-gg.R index 48458d6..8d58e65 100644 --- a/R/anno-gg.R +++ b/R/anno-gg.R @@ -2,8 +2,7 @@ #' @inheritParams ggfit #' @inheritParams new_anno #' @inherit new_anno return -#' @seealso -#' - [ggfit] +#' @seealso [ggfit] #' @examples #' g <- ggplot(mpg, aes(displ, hwy, colour = class)) + #' geom_point() @@ -73,8 +72,6 @@ anno_gg <- function(gg, align_with = "full", clip = NULL, gt = NULL, ) } -#' @seealso -#' - [ggfit2] #' @examples #' # anno_gg2-panel: margins = NULL ------- #' ggheat(m, diff --git a/R/ggfit.R b/R/ggfit.R index 5fb41a7..bd2d55d 100644 --- a/R/ggfit.R +++ b/R/ggfit.R @@ -6,7 +6,7 @@ #' @param clip One of `"on"`, `"inherit"`, or `"off"`, indicating whether to #' clip to the extent out of the viewport, inherit the clipping region from #' `vp`, or turn clipping off altogether. A logical value of `TRUE` corresponds -#' to `"on"` and `FALSE` corresponds to `"off"`. A `NULL` means `"inherit"`. +#' to `"on"` and `FALSE` corresponds to `"off"`. Default: `"inherit"`. #' @param margins Which margin to draw besides the plot in the `vp` viewport. #' This allows for a more precise adjustment of the `clip` feature. Allowed #' values are `r rd_elements(MARGINS)`, When set to `NULL`, it means clip = @@ -79,15 +79,13 @@ ggfit <- function(gg, align_with = "full", clip = NULL, vp = NULL, gt = NULL) { assert_clip(clip) assert_s3_class(vp, "viewport", null_ok = TRUE) # we need a valid viewport to decide the `clip` argument - vp <- vp %||% grid::viewport() + vp <- vp %||% grid::viewport(clip = grid::current.viewport()$clip) margins <- setup_margins(clip, vp) .ggfit(gt, align_with, margins, vp = vp) } setup_margins <- function(clip, vp) { - if (is.null(vp)) { - if (is.null(clip) || identical(clip, "inherit")) clip <- vp$clip - } + if (is.null(clip) || identical(clip, "inherit")) clip <- vp$clip if (isTRUE(clip) || identical(clip, "on")) { NULL } else { @@ -163,7 +161,7 @@ ggfit2 <- function(gg, align_with = "full", .ggfit <- function(gt, align_with, margins = MARGINS, elements = GG_ELEMENTS, vp = NULL) { - if (is.null(vp)) vp <- grid::viewport() + vp <- vp %||% grid::viewport(clip = grid::current.viewport()$clip) grid::pushViewport(vp) on.exit(grid::popViewport()) if (align_with == "full") { diff --git a/README.Rmd b/README.Rmd index 588968e..de7538b 100644 --- a/README.Rmd +++ b/README.Rmd @@ -1,5 +1,7 @@ --- -output: github_document +output: + github_document: + toc: true --- diff --git a/README.html b/README.html index 4f2e0cc..cdf900b 100644 --- a/README.html +++ b/README.html @@ -601,6 +601,16 @@
+anno_gg
and
+anno_gg2
Both function acts similar with other annotation function in +ComplexHeatmap. Both accept a ggplot object and fit it in the +ComplexHeatmap annotation area.
+g <- ggplot(mpg, aes(displ, hwy, colour = class)) +
+ geom_point()
+m <- matrix(rnorm(100), 10)
+
+# anno_gg-panel: clip = "off" -------
+ggheat(m,
+ top_annotation = HeatmapAnnotation(
+ ggplot = anno_gg(g, "panel",
+ clip = "off",
+ height = unit(3, "cm"),
+ show_name = FALSE
+ )
+ )
+)
# anno_gg-panel: clip = "on" --------
+ggheat(m,
+ top_annotation = HeatmapAnnotation(
+ ggplot = anno_gg(g, "panel",
+ clip = "on",
+ height = unit(3, "cm"),
+ show_name = FALSE
+ )
+ )
+)
# anno_gg-plot --------------------
+ggheat(m,
+ top_annotation = HeatmapAnnotation(
+ ggplot = anno_gg(g, "plot",
+ height = unit(3, "cm"),
+ show_name = FALSE
+ )
+ )
+)
+# anno_gg-full --------------------
+ggheat(m,
+ top_annotation = HeatmapAnnotation(
+ ggplot = anno_gg(g, "full",
+ height = unit(3, "cm"),
+ show_name = FALSE
+ )
+ )
+)
anno_gg2
is the same with anno_gg
, it
+differs in terms of its arguments, and allow more precise adjustment of
+the clip feature.
# anno_gg2-panel: margins = NULL -------
+ggheat(m,
+ top_annotation = HeatmapAnnotation(
+ ggplot = anno_gg2(g, "panel",
+ margins = NULL,
+ height = unit(6, "cm"),
+ show_name = FALSE
+ )
+ )
+)
# anno_gg2-panel: margins = "l" --------
+ggheat(m,
+ top_annotation = HeatmapAnnotation(
+ ggplot = anno_gg2(g, "panel",
+ margins = "l",
+ height = unit(6, "cm"),
+ show_name = FALSE
+ )
+ )
+)
# anno_gg2-panel: margins = "r" --------
+ggheat(m,
+ top_annotation = HeatmapAnnotation(
+ ggplot = anno_gg2(g, "panel",
+ margins = "r",
+ height = unit(6, "cm"),
+ show_name = FALSE
+ )
+ )
+)