R/gg_add_zone_perimeters.R

Defines functions gg_add_zone_perimeters

Documented in gg_add_zone_perimeters

#' Add perimeters around the relationship zones
#'
#' Pass it the original ggplot, and this will return it, with the perimeters added.
#' @param g the original ggplot
#' @param L the number of rows (or columns) in the ancestor-match matrices
#' @param perisize the size of the line to color in the perimeters
#' @keywords internal
gg_add_zone_perimeters <- function(
  g,
  L,
  perisize = 0.5
) {

  # determine number of generations
  GenP1 <- ceiling(log(L + 1, base = 2))

  # now get the relationships to include
  num_relat <- c(1, 3, 6, 10, 15)[GenP1]

  # get a tibble of perimeter endpoints
  rzp <- relationship_zone_perimeters() %>%
    filter(zone %in% relationship_zone_names[necessary_generations < GenP1])


  g2 <- g + annotate(
    "rect",
    xmin = rzp$xmin,
    xmax = rzp$xmax,
    ymin = rzp$ymin,
    ymax = rzp$ymax,
    fill = NA,
    colour = "black",
    size = perisize
  )

  g2
}
eriqande/CKMRpop documentation built on Jan. 25, 2024, 2:10 p.m.