Skip to contents

[Experimental]

The with_quad function allows you to adjust the context in which the subtraction - operator is applied within quad_layout(). This function wraps objects to specify their target layout contexts when using - in quad_layout().

Usage

with_quad(x, position = waiver(), main = NULL)

Arguments

x

The object to be added to the layout using the - operator.

position

A string specifying one or more positions- "t", "l", "b", and "r"- to indicate the annotation stack context for the operator -. By default, waiver() is used, which sets the behavior as follows: if the active context in quad_layout() is top or bottom, the operator will also apply to the corresponding bottom or top annotation, respectively. Similarly, if the context is left or right, the operator applies to the right or left annotation. When no annotation stack is active, the context defaults to NULL.

main

A single boolean value indicating whether x should apply to the main plot, used only when position is not NULL. By default, if position is waiver() and the active context of quad_layout() is an annotation stack or the active context of stack_layout is itself, main will be set to TRUE; otherwise, it defaults to FALSE.

Value

The original object with an added attribute that sets the specified layout context.

Examples

set.seed(123)
small_mat <- matrix(rnorm(56), nrow = 7)

# when the active context in `ggheatmap()`/`quad_layout()` is set to `top` or
# `bottom`, by wrapping object with `with_quad()`, the `-` operator will
# apply changes not only to that annotation but also to the opposite one
# (i.e., bottom if top is active, and vice versa). The same principle
# applies to the left and right annotation.
ggheatmap(small_mat) +
    scale_fill_viridis_c() +
    anno_left(size = 0.2) +
    align_dendro(aes(color = branch), k = 3L) +
    # Change the active layout to the left annotation
    anno_top(size = 0.2) +
    align_dendro(aes(color = branch), k = 3L) +
    anno_bottom(size = 0.2) +
    align_dendro(aes(color = branch), k = 3L) -
    # Modify the color scale of all plots in the bottom and the opposite
    # annotation
    # in this way, the `main` argument by default would be `TRUE`
    with_quad(scale_color_brewer(palette = "Dark2", name = "Top and bottom"))
#> → heatmap built with `geom_tile()`


# When the `position` argument is manually set, the
# default value of the `main` argument will be `FALSE`.
ggheatmap(small_mat) +
    scale_fill_viridis_c() +
    anno_left(size = 0.2) +
    align_dendro(aes(color = branch), k = 3L) +
    anno_top(size = 0.2) +
    align_dendro(aes(color = branch), k = 3L) +
    anno_bottom(size = 0.2) +
    align_dendro(aes(color = branch), k = 3L) -
    # Modify the background of all plots in the left and top annotation
    with_quad(theme(plot.background = element_rect(fill = "red")), "tl")
#> → heatmap built with `geom_tile()`