with_quad | R Documentation |
quad_layout()
The with_quad()
function modifies the application context of elements in
ggheatmap()
/quad_layout()
. It controls how objects like themes, scales,
or other plot modifications apply to specific annotation stacks or the main
plot without altering the currently active layout or plot.
with_quad(x, position = waiver(), main = NULL)
x |
An object which can be added to the ggplot, including
schemes. See |
position |
A string specifying one or more positions-
|
main |
A single boolean value indicating whether |
Default Behavior when adding object wrapped with with_quad()
:
For quad_layout()
object:
When ggheatmap()
/quad_layout()
has no active annotation stack, objects
added via +
or -
operate normally without with_quad()
.
When the active annotation stack is set, with_quad()
ensures the applied
object also modifies:
The main plot (by default).
Opposite annotation stacks when using -
.
For stack_layout()
object:
When the active layout is the stack_layout()
itself:
-
operator will apply changes to all plots along the
stack_layout()
, which means if the stack layout is in horizontal
,
-
operator will also add the element to the left
and right
annotation, if the stack layout is in vertical
, -
operator will
also add element to the top
and bottom
annotation.
+
operator won't do anything special.
When the active layout is the nested ggheatmap()
/quad_layout()
, the
+
/-
operator applies the elements to this nested layout, following the
same principles as for ggheatmap()
/quad_layout()
.
The original object with an added attribute that sets the specified context.
set.seed(123)
small_mat <- matrix(rnorm(56), nrow = 7)
# By wrapping object with `with_quad()`, the `+` operator will apply the
# object not only to the active plot in the annotation stack, but also to
# the main plot unless specified by `main` argument otherwise.
ggheatmap(small_mat) +
# initialize the left annotation
anno_left(size = 0.2) +
align_dendro() +
# apply the object not only to the active plot in the annotation stack,
# but also to the main plot
with_quad(theme(plot.background = element_rect(fill = "red")))
# the `-` operator will apply changes not only to the active annotation
# stack 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) +
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"))
# When the `position` argument is manually set, the
# default value of the `main` argument will be `FALSE`.
ggheatmap(small_mat) +
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.