View source: R/heatmap_pairwise.R
| heatmap_pairwise | R Documentation |
Plot a square heatmap from either a full symmetric distance matrix or a tidy
tibble of distances. Rows and columns can optionally be reordered using
either an explicit ordering vector or a function that computes an ordering
(e.g. hierarchical clustering). Dendrograms can be added to the heatmap with
heatmap_add_dendro(). Note that any decoration (e.g. axis labels, fill
scale) should be added to the heatmap before adding dendrograms, as the
latter will modify the plot structure and make it difficult to add further
customization afterwards.
heatmap_pairwise(x, order = NULL)
x |
A square numeric matrix OR a data.frame/tibble with 3 columns:
names1, names2, value (half-matrix representation). The tidy output of
|
order |
Optional ordering specification. Can be:
|
A ggplot object.
heatmap_add_dendro()
example_gt <- load_example_gt("gen_tbl")
# With a pairwise matrix:
fst_dist <- example_gt %>%
group_by(population) %>%
pairwise_pop_fst(method = "Nei87", type = "pairwise")
heatmap_pairwise(fst_dist)
# Explicit ordering
heatmap_pairwise(
fst_dist,
order = rev(rownames(fst_dist))
) +
ggplot2::scale_fill_viridis_c()
# Hierarchical clustering
heatmap_pairwise(
fst_dist,
order = function(x) {
stats::hclust(stats::as.dist(x), method = "complete")
}
)
# With a tidy tibble of distances:
fst_tidy <- example_gt %>%
group_by(population) %>%
pairwise_pop_fst(method = "Nei87", type = "tidy")
heatmap_pairwise(fst_tidy)
heatmap_pairwise(
fst_tidy,
order = function(x) {
stats::hclust(stats::as.dist(x))
}
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.