This vignette demonstrates how to calculate and visualize relatedness
matrices for animal pedigrees using functions from the BGmisc and
ggpedigree packages. We focus on Kluane Red Squirrel Project data, but
the workflow generalizes to any pedigree dataset. The
ggRelatednessMatrix
function is a new addition to the
ggpedigree package, which provides a flexible and visually appealing way
to explore patterns of genetic and mitochondrial relatedness within
families. This function is designed to work seamlessly with the
ped2add
and ped2mit
functions from the BGmisc
package, which calculate additive genetic and mitochondrial relatedness
matrices, respectively.
We will use the new ggRelatednessMatrix function to create ggplot2-based heatmaps of relatedness matrices, inspired by the approaches in the original squirrel population analyses.
First, load pedigree data and required libraries. The example data is the life‐history and reproductive metrics for 7,799 individual red squirrels from the Kluane Red Squirrel Project (1987–present). See the redsquirrels data documentation for more details.
You can adjust clustering, color scales, labels, and more using the config list. For example, to turn off clustering:
p_add_noclust <- ggRelatednessMatrix(
add_mat,
config = list(cluster = FALSE, title = "Additive Relatedness (No Clustering)")
)
p_add_noclust
For comparison, here is how the same matrix would be plotted in corrplot, as in earlier squirrel analyses:
if (requireNamespace("corrplot", quietly = TRUE)) {
corrplot::corrplot(
as.matrix(add_mat),
method = "color",
type = "lower",
col.lim = c(0, 1.25),
is.corr = FALSE,
title = "Additive Relatedness",
order = "hclust",
col = corrplot::COL1("Reds", 100),
tl.pos = "l", tl.col = "black", tl.srt = 5, tl.cex = 0.2,
mar = c(0, 0, 2, 0)
)
}
The ggRelatednessMatrix function provides a flexible and visually appealing way to explore patterns of genetic and mitochondrial relatedness within families. This workflow integrates seamlessly with tools from BGmisc and ggpedigree, supporting reproducible, publication-quality visualization for quantitative genetic analysis.