-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathESR_corporate_colours.R
78 lines (64 loc) · 1.79 KB
/
ESR_corporate_colours.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
78
#' ESR colours for corporate brand
#'
#'@example data(iris)
#'
#' ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, fill = Species))+
#' geom_point()+
#' scale_fill_branded_ESR()+
#' theme_ESR()
branded_pal_ESR <- function(
primary = "blue"
, other = "green"
, direction = 1
) {
# https://www.garrickadenbuie.com/blog/custom-discrete-color-scales-for-ggplot2/
#
#
ESR_branded_colors <- list(
"blue"="#0097db"
, "green" = "#85C659"
, "red" = "#ec1515"
, "yellow" = "#febf2a"
, "purple" = "#784f96"
, "lightgreen" ="#1abcc1"
)
stopifnot(primary %in% names(ESR_branded_colors))
function(n) {
if (n > 6) warning("Branded Colour Palette only has 6 colors.")
if (n == 2) {
other <- if (!other %in% names(ESR_branded_colors)) {
other
} else {
ESR_branded_colors[other]
}
color_list <- c(other, ESR_branded_colors[primary])
} else {
color_list <- ESR_branded_colors[1:n]
}
color_list <- unname(unlist(color_list))
if (direction >= 0) color_list else rev(color_list)
}
}
# scale_fill_branded_ESR <- function(
# primary = "blue"
# , other = "lightgreen"
# , direction = 1
# ) {
# # https://www.garrickadenbuie.com/blog/custom-discrete-color-scales-for-ggplot2/
# ggplot2::continuous_scale(
# "fill", "branded"
# , branded_pal_ESR(primary, other, direction)
# )
# }
# scale_color_gradientn(colours = branded_pal_ESR()(2))
scale_colour_branded_ESR <- function(
primary = "blue"
, other = "green"
, direction = 1
) {
# https://www.garrickadenbuie.com/blog/custom-discrete-color-scales-for-ggplot2/
ggplot2::discrete_scale(
"colour", "branded"
, branded_pal_ESR(primary, other, direction)
)
}