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")
Run the code above in your browser using DataLab