-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
oreilly-colours.R
38 lines (31 loc) · 842 Bytes
/
oreilly-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
library(farver)
library(dplyr, warn.conflicts = FALSE)
oreilly <- tribble(
~ name, ~r, ~g, ~b,
"blue", 0, 113, 188,
"orange", 247, 147, 30,
"red", 193, 39, 45,
"green", 0, 146, 68,
"yellow", 255, 222, 0,
"purple", 153, 0, 204
)
oreilly$col <- encode_colour(oreilly[c("r", "g", "b")])
tint <- function(col, tint) {
n <- length(tint)
col_Lab <- decode_colour(col, to = "Lab")
white_Lab <- decode_colour(white, to = "Lab")
encode_colour(
col_Lab[rep(1,n), ] * tint + white_Lab[rep(1,n), ] * (1 - tint),
from = "Lab"
)
}
tints <- seq(0.1, 1, length.out = 10)
oreilly |>
group_by(name) |>
summarize(
tint = paste0("t", tints * 100),
colour = tint(col, tints),
.groups = "drop"
) |>
tidyr::pivot_wider(names_from = tint, values_from = colour)
scales::show_col(tint(oreilly$col[5], tints))