-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add color_blind() #181
Comments
Functions: #' Provide Colorblind Compliant Colors
#'
#' 8 Hex RGB color defintions suitable for charts for colorblind people.
#'
#' @export
color_blind <- function(){
c("#000000", "#E69F00", "#56B4E9",
"#009E73", "#F0E442", "#0072B2",
"#D55E00", "#CC79A7")
}
# Fill
ts_scale_fill_colorblind = function(.ColorList = 2L:8L, ...){
ggplot2::scale_fill_discrete(..., type = color_blind())
}
# Color
ts_scale_color_colorblind = function(.ColorList = 2L:8L, ...){
ggplot2::scale_color_discrete(..., type = color_blind())
} Example: library(tidyverse)
ggplot(
diamonds,
aes(clarity, fill = cut)
) +
geom_bar(position = "dodge") +
ts_scale_fill_colorblind() |
Final functions #' 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
#' @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
#' @export
td_scale_color_colorblind = function(..., theme = "td") {
pal <- switch(theme,
"td" = unname(color_blind()) %>% rep(100)
)
ggplot2::scale_color_manual(values = pal)
}
|
spsanderson
added a commit
that referenced
this issue
May 10, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: