Skip to content

Commit

Permalink
add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Jun 22, 2024
1 parent 5e7b21b commit 508293f
Show file tree
Hide file tree
Showing 17 changed files with 412 additions and 21 deletions.
5 changes: 1 addition & 4 deletions R/anno-gg.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions R/ggfit.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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") {
Expand Down
4 changes: 3 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
output: github_document
output:
github_document:
toc: true
---

<!-- README.md is generated from README.Rmd. Please edit that file -->
Expand Down
127 changes: 127 additions & 0 deletions README.html

Large diffs are not rendered by default.

151 changes: 151 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

- [eheat](#eheat)
- [Installation](#installation)
- [ggheat](#ggheat)
- [gganno](#gganno)
- [`anno_gg` and `anno_gg2`](#anno_gg-and-anno_gg2)

<!-- README.md is generated from README.Rmd. Please edit that file -->

# eheat
Expand Down Expand Up @@ -535,3 +541,148 @@ draw(Heatmap(small_mat,
```

<img src="man/figures/README-Heatmap_gganno-1.png" width="100%" />

## `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
)
)
)
```

<img src="man/figures/README-anno_gg-panel-1.png" width="100%" />

``` 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
)
)
)
```

<img src="man/figures/README-anno_gg-panel-clip-1.png" width="100%" />

``` r
# anno_gg-plot --------------------
ggheat(m,
top_annotation = HeatmapAnnotation(
ggplot = anno_gg(g, "plot",
height = unit(3, "cm"),
show_name = FALSE
)
)
)
```

<img src="man/figures/README-anno_gg-plot-1.png" width="100%" />

``` r

# anno_gg-full --------------------
ggheat(m,
top_annotation = HeatmapAnnotation(
ggplot = anno_gg(g, "full",
height = unit(3, "cm"),
show_name = FALSE
)
)
)
```

<img src="man/figures/README-anno_gg-plot-2.png" width="100%" />

`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
)
)
)
```

<img src="man/figures/README-anno_gg2-panel1-1.png" width="100%" />

``` 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
)
)
)
```

<img src="man/figures/README-anno_gg2-panel2-1.png" width="100%" />

``` 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
)
)
)
```

<img src="man/figures/README-anno_gg2-panel3-1.png" width="100%" />

``` r
# anno_gg2-plot ---------------------
ggheat(m,
top_annotation = HeatmapAnnotation(
ggplot = anno_gg2(g, "plot",
height = unit(6, "cm"),
show_name = FALSE
)
)
)
```

<img src="man/figures/README-anno_gg2-plot-1.png" width="100%" />

``` r
# anno_gg2-full --------------------
ggheat(m,
top_annotation = HeatmapAnnotation(
ggplot = anno_gg2(g, "full",
height = unit(6, "cm"),
show_name = FALSE
)
)
)
```

<img src="man/figures/README-anno_gg2-full-1.png" width="100%" />
10 changes: 2 additions & 8 deletions man/anno_gg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added man/figures/README-anno_gg-panel-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-anno_gg-panel-clip-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-anno_gg-plot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-anno_gg-plot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-anno_gg2-full-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-anno_gg2-panel1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-anno_gg2-panel2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-anno_gg2-panel3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-anno_gg2-plot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion man/ggfit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 123 additions & 1 deletion vignettes/eheat.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
title: "eheat"
output: rmarkdown::html_vignette
output:
rmarkdown::html_vignette:
toc: true
vignette: >
%\VignetteIndexEntry{eheat}
%\VignetteEngine{knitr::rmarkdown}
Expand Down Expand Up @@ -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
)
)
)
```

0 comments on commit 508293f

Please sign in to comment.