-
Notifications
You must be signed in to change notification settings - Fork 3
/
pallette-color-blind.R
77 lines (71 loc) · 1.83 KB
/
pallette-color-blind.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#' Provide Colorblind Compliant Colors
#'
#' @author Steven P. Sanderson II, MPH
#'
#' @details
#' This function is used in others in order to help render plots for those that
#' are color blind.
#'
#' @description
#' 8 Hex RGB color definitions suitable for charts for colorblind people.
#'
#' @examples
#' color_blind()
#'
#' @return
#' A vector of 8 Hex RGB definitions.
#'
#' @export
color_blind <- function(){
c("#000000", "#E69F00", "#56B4E9",
"#009E73", "#F0E442", "#0072B2",
"#D55E00", "#CC79A7")
}
#' Provide Colorblind Compliant Colors
#'
#' @author Steven P. Sanderson II, MPH
#'
#' @details
#' This function is used in others in order to help render plots for those that
#' are color blind.
#'
#' @description
#' 8 Hex RGB color definitions suitable for charts for colorblind people.
#'
#' @param ... Data passed in from a `ggplot` object
#' @param theme Right now this is `hr` only. Anything else will render an error.
#'
#' @return
#' A `gggplot` layer
#'
#' @export
hr_scale_fill_colorblind <- function(..., theme = "hr") {
pal <- switch(theme,
"hr" = unname(color_blind()) %>% rep(100)
)
ggplot2::scale_fill_manual(values = pal)
}
#' Provide Colorblind Compliant Colors
#'
#' @author Steven P. Sanderson II, MPH
#'
#' @details
#' This function is used in others in order to help render plots for those that
#' are color blind.
#'
#' @description
#' 8 Hex RGB color definitions suitable for charts for colorblind people.
#'
#' @param ... Data passed in from a `ggplot` object
#' @param theme Right now this is `hr` only. Anything else will render an error.
#'
#' @return
#' A `gggplot` layer
#'
#' @export
hr_scale_color_colorblind = function(..., theme = "hr") {
pal <- switch(theme,
"hr" = unname(color_blind()) %>% rep(100)
)
ggplot2::scale_color_manual(values = pal)
}