R/palette-color-blind.R

Defines functions td_scale_color_colorblind td_scale_fill_colorblind color_blind

Documented in color_blind td_scale_color_colorblind td_scale_fill_colorblind

#' Provide Colorblind Compliant Colors
#'
#' 8 Hex RGB color definitions suitable for charts for colorblind people.
#'
#' @export
color_blind <- function() {
  c(
    "#000000", "#E69F00", "#56B4E9",
    "#009E73", "#F0E442", "#0072B2",
    "#D55E00", "#CC79A7"
  )
}

#' Provide Colorblind Compliant Colors
#'
#' @param theme This defaults to `td` and that is the only allowed value
#' @param ... Data passed to the function
#'
#' @export
td_scale_fill_colorblind <- function(..., theme = "td") {
  pal <- switch(theme,
    "td" = unname(color_blind()) %>% rep(100)
  )

  ggplot2::scale_fill_manual(values = pal)
}

#' Provide Colorblind Compliant Colors
#'
#' @param theme This defaults to `td` and that is the only allowed value
#' @param ... Data passed to the function
#'
#' @export
td_scale_color_colorblind <- function(..., theme = "td") {
  pal <- switch(theme,
    "td" = unname(color_blind()) %>% rep(100)
  )

  ggplot2::scale_color_manual(values = pal)
}

Try the TidyDensity package in your browser

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

TidyDensity documentation built on Nov. 2, 2023, 5:38 p.m.