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 @@ +

eheat

@@ -1043,5 +1053,122 @@

gganno

#> ℹ convert simple vector to one-column matrix +

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
+    )
+  )
+)
+ + +
# anno_gg2-plot ---------------------
+ggheat(m,
+  top_annotation = HeatmapAnnotation(
+    ggplot = anno_gg2(g, "plot",
+      height = unit(6, "cm"),
+      show_name = FALSE
+    )
+  )
+)
+ + +
# anno_gg2-full --------------------
+ggheat(m,
+  top_annotation = HeatmapAnnotation(
+    ggplot = anno_gg2(g, "full",
+      height = unit(6, "cm"),
+      show_name = FALSE
+    )
+  )
+)
+ + diff --git a/README.md b/README.md index e5a2d87..893d155 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ +- [eheat](#eheat) + - [Installation](#installation) + - [ggheat](#ggheat) + - [gganno](#gganno) + - [`anno_gg` and `anno_gg2`](#anno_gg-and-anno_gg2) + # eheat @@ -535,3 +541,148 @@ draw(Heatmap(small_mat, ``` + +## `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. + +``` r +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 + ) + ) +) +``` + + + +``` r +# anno_gg-panel: clip = "on" -------- +ggheat(m, + top_annotation = HeatmapAnnotation( + ggplot = anno_gg(g, "panel", + clip = "on", + height = unit(3, "cm"), + show_name = FALSE + ) + ) +) +``` + + + +``` r +# anno_gg-plot -------------------- +ggheat(m, + top_annotation = HeatmapAnnotation( + ggplot = anno_gg(g, "plot", + height = unit(3, "cm"), + show_name = FALSE + ) + ) +) +``` + + + +``` r + +# 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. + +``` r +# anno_gg2-panel: margins = NULL ------- +ggheat(m, + top_annotation = HeatmapAnnotation( + ggplot = anno_gg2(g, "panel", + margins = NULL, + height = unit(6, "cm"), + show_name = FALSE + ) + ) +) +``` + + + +``` r +# anno_gg2-panel: margins = "l" -------- +ggheat(m, + top_annotation = HeatmapAnnotation( + ggplot = anno_gg2(g, "panel", + margins = "l", + height = unit(6, "cm"), + show_name = FALSE + ) + ) +) +``` + + + +``` r +# anno_gg2-panel: margins = "r" -------- +ggheat(m, + top_annotation = HeatmapAnnotation( + ggplot = anno_gg2(g, "panel", + margins = "r", + height = unit(6, "cm"), + show_name = FALSE + ) + ) +) +``` + + + +``` r +# anno_gg2-plot --------------------- +ggheat(m, + top_annotation = HeatmapAnnotation( + ggplot = anno_gg2(g, "plot", + height = unit(6, "cm"), + show_name = FALSE + ) + ) +) +``` + + + +``` r +# anno_gg2-full -------------------- +ggheat(m, + top_annotation = HeatmapAnnotation( + ggplot = anno_gg2(g, "full", + height = unit(6, "cm"), + show_name = FALSE + ) + ) +) +``` + + diff --git a/man/anno_gg.Rd b/man/anno_gg.Rd index 027caf3..978cf60 100644 --- a/man/anno_gg.Rd +++ b/man/anno_gg.Rd @@ -37,7 +37,7 @@ Must be a string of "panel", "plot", "full".} \item{clip}{One of \code{"on"}, \code{"inherit"}, or \code{"off"}, indicating whether to clip to the extent out of the viewport, inherit the clipping region from \code{vp}, or turn clipping off altogether. A logical value of \code{TRUE} corresponds -to \code{"on"} and \code{FALSE} corresponds to \code{"off"}. A \code{NULL} means \code{"inherit"}.} +to \code{"on"} and \code{FALSE} corresponds to \code{"off"}. Default: \code{"inherit"}.} \item{gt}{A \link[ggplot2:ggplotGrob]{gtable} object.} @@ -165,11 +165,5 @@ ggheat(m, ) } \seealso{ -\itemize{ -\item \link{ggfit} -} - -\itemize{ -\item \link{ggfit2} -} +\link{ggfit} } diff --git a/man/figures/README-anno_gg-panel-1.png b/man/figures/README-anno_gg-panel-1.png new file mode 100644 index 0000000..7032d52 Binary files /dev/null and b/man/figures/README-anno_gg-panel-1.png differ diff --git a/man/figures/README-anno_gg-panel-clip-1.png b/man/figures/README-anno_gg-panel-clip-1.png new file mode 100644 index 0000000..944df7a Binary files /dev/null and b/man/figures/README-anno_gg-panel-clip-1.png differ diff --git a/man/figures/README-anno_gg-plot-1.png b/man/figures/README-anno_gg-plot-1.png new file mode 100644 index 0000000..e13b677 Binary files /dev/null and b/man/figures/README-anno_gg-plot-1.png differ diff --git a/man/figures/README-anno_gg-plot-2.png b/man/figures/README-anno_gg-plot-2.png new file mode 100644 index 0000000..88ff009 Binary files /dev/null and b/man/figures/README-anno_gg-plot-2.png differ diff --git a/man/figures/README-anno_gg2-full-1.png b/man/figures/README-anno_gg2-full-1.png new file mode 100644 index 0000000..e2e1152 Binary files /dev/null and b/man/figures/README-anno_gg2-full-1.png differ diff --git a/man/figures/README-anno_gg2-panel1-1.png b/man/figures/README-anno_gg2-panel1-1.png new file mode 100644 index 0000000..fffe675 Binary files /dev/null and b/man/figures/README-anno_gg2-panel1-1.png differ diff --git a/man/figures/README-anno_gg2-panel2-1.png b/man/figures/README-anno_gg2-panel2-1.png new file mode 100644 index 0000000..27475c5 Binary files /dev/null and b/man/figures/README-anno_gg2-panel2-1.png differ diff --git a/man/figures/README-anno_gg2-panel3-1.png b/man/figures/README-anno_gg2-panel3-1.png new file mode 100644 index 0000000..8dcaa0e Binary files /dev/null and b/man/figures/README-anno_gg2-panel3-1.png differ diff --git a/man/figures/README-anno_gg2-plot-1.png b/man/figures/README-anno_gg2-plot-1.png new file mode 100644 index 0000000..89cab06 Binary files /dev/null and b/man/figures/README-anno_gg2-plot-1.png differ diff --git a/man/ggfit.Rd b/man/ggfit.Rd index 8832109..4f47d76 100644 --- a/man/ggfit.Rd +++ b/man/ggfit.Rd @@ -25,7 +25,7 @@ Must be a string of "panel", "plot", "full".} \item{clip}{One of \code{"on"}, \code{"inherit"}, or \code{"off"}, indicating whether to clip to the extent out of the viewport, inherit the clipping region from \code{vp}, or turn clipping off altogether. A logical value of \code{TRUE} corresponds -to \code{"on"} and \code{FALSE} corresponds to \code{"off"}. A \code{NULL} means \code{"inherit"}.} +to \code{"on"} and \code{FALSE} corresponds to \code{"off"}. Default: \code{"inherit"}.} \item{vp}{A \link[grid:viewport]{viewport} object.} diff --git a/vignettes/eheat.Rmd b/vignettes/eheat.Rmd index 31f6ac7..1f17f65 100644 --- a/vignettes/eheat.Rmd +++ b/vignettes/eheat.Rmd @@ -1,6 +1,8 @@ --- title: "eheat" -output: rmarkdown::html_vignette +output: + rmarkdown::html_vignette: + toc: true vignette: > %\VignetteIndexEntry{eheat} %\VignetteEngine{knitr::rmarkdown} @@ -431,3 +433,123 @@ draw(Heatmap(small_mat, ), merge_legends = TRUE) ``` +## `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. + +```{r anno_gg-panel, fig.height=4, fig.width=5} +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 + ) + ) +) +``` + +```{r anno_gg-panel-clip, fig.height=4, fig.width=5} +# anno_gg-panel: clip = "on" -------- +ggheat(m, + top_annotation = HeatmapAnnotation( + ggplot = anno_gg(g, "panel", + clip = "on", + height = unit(3, "cm"), + show_name = FALSE + ) + ) +) +``` + +```{r anno_gg-plot, fig.height=4, fig.width=5} +# 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. +```{r anno_gg2-panel1, fig.height=4, fig.width=5} +# anno_gg2-panel: margins = NULL ------- +ggheat(m, + top_annotation = HeatmapAnnotation( + ggplot = anno_gg2(g, "panel", + margins = NULL, + height = unit(6, "cm"), + show_name = FALSE + ) + ) +) +``` + +```{r anno_gg2-panel2, fig.height=4, fig.width=5} +# anno_gg2-panel: margins = "l" -------- +ggheat(m, + top_annotation = HeatmapAnnotation( + ggplot = anno_gg2(g, "panel", + margins = "l", + height = unit(6, "cm"), + show_name = FALSE + ) + ) +) +``` + +```{r anno_gg2-panel3, fig.height=4, fig.width=5} +# anno_gg2-panel: margins = "r" -------- +ggheat(m, + top_annotation = HeatmapAnnotation( + ggplot = anno_gg2(g, "panel", + margins = "r", + height = unit(6, "cm"), + show_name = FALSE + ) + ) +) +``` + +```{r anno_gg2-plot, fig.height=4, fig.width=5} +# anno_gg2-plot --------------------- +ggheat(m, + top_annotation = HeatmapAnnotation( + ggplot = anno_gg2(g, "plot", + height = unit(6, "cm"), + show_name = FALSE + ) + ) +) +``` + +```{r anno_gg2-full, fig.height=4, fig.width=5} +# anno_gg2-full -------------------- +ggheat(m, + top_annotation = HeatmapAnnotation( + ggplot = anno_gg2(g, "full", + height = unit(6, "cm"), + show_name = FALSE + ) + ) +) +```