R/scale_fill_distruct.R

Defines functions scale_fill_distruct

Documented in scale_fill_distruct

#' Scale constructor using the distruct colours
#'
#' A wrapper around [ggplot2::scale_fill_manual()], using the distruct colours
#' from [`distruct_colours`].
#' @param guide guide function passed to [ggplot2::scale_fill_manual()].
#' Defaults to "none", set to "legend" if a legend is required.
#' @param ... further parameters to be passed to [ggplot2::scale_fill_manual()]
#' @returns a scale constructor to be used with ggplot
#' @export
#' @examples
#' library(ggplot2)
#' # Create a gen_tibble of lobster genotypes
#' bed_file <-
#'   system.file("extdata", "lobster", "lobster.bed", package = "tidypopgen")
#' lobsters <- gen_tibble(bed_file,
#'   backingfile = tempfile("lobsters"),
#'   quiet = TRUE
#' )
#'
#' # Remove monomorphic loci and impute
#' lobsters <- lobsters %>% select_loci_if(loci_maf(genotypes) > 0)
#' lobsters <- gt_impute_simple(lobsters, method = "mode")
#'
#' # Create PCA object
#' pca <- gt_pca_partialSVD(lobsters)
#'
#' # Colour by population
#' autoplot(pca, type = "scores") +
#'   aes(colour = lobsters$population) + scale_fill_distruct()
scale_fill_distruct <- function(guide = "none", ...) {
  ggplot2::scale_fill_manual(
    values = tidypopgen::distruct_colours,
    guide = guide,
    ...
  )
}

Try the tidypopgen package in your browser

Any scripts or data that you put into this service are public.

tidypopgen documentation built on Aug. 28, 2025, 1:08 a.m.