Skip to contents

Layout operator

Usage

# S4 method for class 'Layout,ANY'
e1 & e2

# S4 method for class 'Layout,ANY'
e1 - e2

Arguments

e1

A layout_heatmap() or layout_stack() object.

e2

An object to be added to the plot.

Value

A modified Layout object.

Details

In order to reduce code repetition ggalign provides two operators for adding ggplot elements (geoms, themes, facets, etc.) to multiple/all plots in layout_heatmap() or layout_stack() object.

Like patchwork, & add the element to all plots in the plot. If the element is a theme, this will also modify the layout theme.

Unlike patchwork, the - operator adds ggplot2 elements (geoms, themes, facets, etc.) rather than a ggplot plot. The key difference between & and - is in how they behave in layout_heatmap(). The - operator only applies the element to the current active context in layout_heatmap(). Using - might seem unintuitive if you think of the operator as "subtract", the underlying reason is that - is the only operator in the same precedence group as +.

Examples

mat <- matrix(rnorm(81), nrow = 9)
ggheatmap(mat) +
    hmanno("top") +
    align_dendro() &
    theme(panel.border = element_rect(
        colour = "red", fill = NA, linewidth = unit(2, "mm")
    ))

ggheatmap(mat) +
    hmanno("top") +
    align_dendro() -
    theme(panel.border = element_rect(
        colour = "red", fill = NA, linewidth = unit(2, "mm")
    ))