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 inquad_layout()
istop
orbottom
, the operator will also apply to the correspondingbottom
ortop
annotation, respectively. Similarly, if the context isleft
orright
, the operator applies to theright
orleft
annotation. When no annotation stack is active, the context defaults toNULL
.- main
A single boolean value indicating whether
x
should apply to the main plot, used only whenposition
is notNULL
. By default, ifposition
iswaiver()
and the active context ofquad_layout()
is an annotation stack or the active context ofstack_layout
is itself,main
will be set toTRUE
; otherwise, it defaults toFALSE
.
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()`