Code
library(ggalign)
#> Loading required package: ggplot2
set.seed(123)
<- matrix(rnorm(56), nrow = 7)
small_mat rownames(small_mat) <- paste0("row", seq_len(nrow(small_mat)))
colnames(small_mat) <- paste0("column", seq_len(ncol(small_mat)))
library(ggalign)
#> Loading required package: ggplot2
set.seed(123)
<- matrix(rnorm(56), nrow = 7)
small_mat rownames(small_mat) <- paste0("row", seq_len(nrow(small_mat)))
colnames(small_mat) <- paste0("column", seq_len(ncol(small_mat)))
ggheatmap(small_mat)
#> → heatmap built with `geom_tile()`
ggheatmap(small_mat) +
anno_top() +
align_dendro(aes(color = branch), k = 3) +
geom_point(aes(color = branch, y = y)) +
scale_color_brewer(palette = "Dark2")
#> → heatmap built with `geom_tile()`
ggheatmap(small_mat) +
anno_top() +
align_kmeans(3L)
#> → heatmap built with `geom_tile()`
ggheatmap(small_mat) +
anno_top() +
align_group(sample(letters[1:4], ncol(small_mat), replace = TRUE))
#> → heatmap built with `geom_tile()`
Here, we ordered the heatmap rows based on the row means.
ggheatmap(small_mat) +
anno_left() +
align_order(rowMeans)
#> → heatmap built with `geom_tile()`
ggheatmap(small_mat) +
anno_top() +
align_dendro(aes(color = branch), k = 3) +
geom_point(aes(color = branch, y = y)) +
scale_color_brewer(palette = "Dark2") +
ggalign(mapping = aes(y = value)) +
geom_boxplot(aes(factor(.x), fill = .panel)) +
scale_fill_brewer(palette = "Dark2")
#> → heatmap built with `geom_tile()`
ggheatmap(small_mat) +
anno_top(size = 0.5) +
align_dendro(aes(color = branch), k = 3L) +
ggalign(rowSums, aes(y = value)) +
geom_bar(stat = "identity", aes(fill = factor(.panel))) +
scale_fill_brewer(name = NULL, palette = "Dark2") +
anno_left(size = 0.5) +
align_dendro(aes(color = branch), size = 0.5, k = 4L) +
ggalign(rowSums, aes(x = value)) +
geom_bar(
aes(y = .y, fill = factor(.y)),
stat = "identity",
orientation = "y"
+
) scale_fill_brewer(name = NULL, palette = "Paired", guide = "none")
#> → heatmap built with `geom_tile()`
stack_alignh(small_mat) +
(ggheatmap() +
ggheatmap() &
theme(axis.text.x = element_text(angle = -60, hjust = 0))) +
stack_active() +
align_dendro(aes(color = branch), k = 4L, size = 0.2) +
scale_color_brewer(palette = "Dark2")
#> → heatmap built with `geom_tile()`
#> → heatmap built with `geom_tile()`
stack_alignv(small_mat) -
scheme_theme(
axis.text.x = element_blank(),
axis.ticks.x = element_blank()
+
) align_dendro(aes(color = branch), k = 4L, size = 0.2) +
scale_color_brewer(palette = "Dark2") +
ggheatmap() +
ggheatmap() +
theme(axis.text.x = element_text(angle = -60, hjust = 0))
#> → heatmap built with `geom_tile()`
#> → heatmap built with `geom_tile()`
ggside(mpg, aes(displ, hwy, colour = class)) -
# set default theme for all plots in the layout
scheme_theme(theme_bw()) +
geom_point(size = 2) +
# add top annotation
anno_top(size = 0.3) -
# set default theme for the top annotation
scheme_theme(theme_no_axes("tb")) +
# add a plot in the top annotation
ggfree() +
geom_density(aes(displ, y = after_stat(density), colour = class), position = "stack") +
anno_right(size = 0.3) -
# set default theme for the right annotation
scheme_theme(theme_no_axes("lr")) +
# add a plot in the right annotation
ggfree() +
geom_density(aes(x = after_stat(density), hwy, colour = class),
position = "stack"
+
) theme(axis.text.x = element_text(angle = 90, vjust = .5)) &
scale_color_brewer(palette = "Dark2")