forked from hadley/r4ds
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoreilly-colours.R
More file actions
59 lines (52 loc) · 885 Bytes
/
oreilly-colours.R
File metadata and controls
59 lines (52 loc) · 885 Bytes
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
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))