/
ios-colours.R
503 lines (464 loc) · 17.6 KB
/
ios-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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
ios_background_cols <- list(white = "#ffffff",
dark_jungle_green = "#1c1c1e",
black = "#000000")
ios_background_palette <- unname(unlist(ios_background_cols))
ios_text_on_light_cols <- list(label = "#000000", # black
secondaryLabel = "#8a8a8e", # oslo.gray
tertiaryLabel = "#c4c4c6", # ghost
quaternaryLabel = "#dcdcdd" # gainsboro
)
ios_text_on_light_palette <- unname(unlist(ios_text_on_light_cols))
ios_text_on_dark_cols <- list(label = "#ffffff", # white
secondaryLabel = "#8d8d93", # oslo.gray
tertiaryLabel = "#47474a", # steel.gray
quaternaryLabel = "#2a2a2c" # jaguar
)
ios_text_on_dark_palette <- unname(unlist(ios_text_on_dark_cols))
ios_light_cols <- list(azure = "#007aff", # 1
ufo.green = "#34c759", # 2
iris = "#5856d6", # 3
safety.orange = "#ff9500", # 4
radical.red = "#ff2d55", # 5
medium.orchid = "#af52de", # 6
red.orange = "#ff3b30", # 7
maya.blue = "#5ac8fa", # 8
tangerine = "#ffcc00") # 9
ios_cols_order <- list(default = 1:9,
contrast = c(1, 2, 5, 6, 4, 8, 3, 7, 9 ))
ios_light_palette <- unname(unlist(ios_light_cols))
ios_accessible_light_cols <- list(palatinate.blue = "#0040dd",
salem = "#248a3d",
governor.bay = "#3634a3",
mahogany = "#c93400",
crimson = "#d30f45",
vivid.violet = "#8944ab",
harvard.crimson = "#d70015",
allports = "#0071a4",
chelsea.gem = "#a05a00")
ios_accessible_light_palette <- unname(unlist(ios_accessible_light_cols))
ios_dark_cols <- list(cool.blue = "#0a84ff",
ufo.green = "#30d158",
majorelle.blue = "#5e5ce6",
california = "#ff9f0a",
radical.red = "#ff375f",
medium.orchid = "#bf5af2",
coral.red = "#ff453a",
maya.blue = "#64d2ff",
gold = "#ffd60a")
ios_dark_palette <- unname(unlist(ios_dark_cols))
ios_accessible_dark_cols <- list(picton.blue = "#409cff",
ufo.green = "#30db5b",
faded.blue = "#7d7aff",
yellow.orange = "#ffb340",
brink.pink = "#ff6482",
heliotrope = "#da8fff",
pastel.red = "#ff6961",
maya.blue = "#70d7ff",
turbo = "#ffd426")
ios_accessible_dark_palette <- unname(unlist(ios_accessible_dark_cols))
#' @title
#' iOS Color Palettes
#'
#' @md
#' @description
#' Set of color palettes based on
#' [iOS System Colors](https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/color/).
#' General information about each palette can be found in the
#' [colors](../articles/colors.html) vignette.
#'
#' @details
#' These functions are ideal for accessing the raw color values, and can be
#' used within functions where raw color values are needed, e.g., [plot].
#' In order to use them with `ggplot` functions, you must utilize one of
#' the followings:
#'
#' - [scale_colour_ios_light]
#' - [scale_colour_ios_dark]
#' - [scale_colour_ios_gray_light]
#' - [scale_colour_ios_gray_dark]
#'
#' @param accessible Indicates whether the accessible set of colors should be used
#' @param order Indicates the order of colors in the palette
#' @rdname ios_colour_palettes
#'
#' @examples
#' library(scales)
#' scales::show_col(
#' ios_light_pal(order = "default", accessible = FALSE)(9),
#' borders = NA, labels = FALSE)
#' scales::show_col(
#' ios_light_pal(order = "default", accessible = TRUE)(9),
#' borders = NA, labels = FALSE)
#'
#' scales::show_col(
#' ios_light_pal(order = "contrast", accessible = FALSE)(9),
#' borders = NA, labels = FALSE)
#' scales::show_col(
#' ios_light_pal(order = "contrast", accessible = TRUE)(9),
#' borders = NA, labels = FALSE)
#'
#' @import scales
#' @export
ios_light_pal <- function(order = "contrast", accessible = FALSE) {
if (accessible) {
scales::manual_pal(ios_accessible_light_palette[ios_cols_order[[order]]])
}else{
scales::manual_pal(ios_light_palette[ios_cols_order[[order]]])
}
}
#' iOS Light Color Scales
#' @md
#' @description
#'
#' These scales meant to be used with light themes, e.g, `theme_sf_light()`.
#' While they can be used with dark themes, in general, we recommend pairing
#' `scale_colour_*_light`s with light themes for better clarity and contrast.
#'
#' **Notes**
#' - *While iOS color palettes provide a total of 9 colors, we do not
#' recommend using them for more than 6 groups. The last three colors often
#' collide with other colors in the palette and may affect the clarity of your
#' visualization.*
#' - See [iOS colors](ios_colour_palettes.html) for more details on raw colors.
#'
#' @param accessible Indicates whether the accessible set of colors should be
#' used
#' @param order Indicates the order of colors in the palette
#'
#' @md
#' @inheritDotParams ggplot2::discrete_scale -expand -position
#' @rdname scale_colour_ios_light
#' @family colour scales
#'
#' @examples \dontrun{
#'
#' library(ggplot2)
#'
#' ggplot(mtcars, aes(y = mpg, x = as.factor(cyl))) +
#' geom_boxplot(aes(color = as.factor(cyl), fill = as.factor(cyl))) +
#' labs(x = "Miles Per Gallon", y = "MPG",
#' fill = "Number of Cylinders",
#' color = "Number of Cylinders",
#' title = "Fuel Economy",
#' subtitle = "Fuel economy declines as engines gets bigger",
#' caption = "Data from the 1974 Motor Trend US magazine.") +
#' theme_sf_light() +
#' scale_fill_ios_light() +
#' scale_colour_ios_light()
#' }
#' @export
scale_colour_ios_light <- function(order = "contrast", accessible = FALSE, ...) {
if (accessible) {
ggplot2::discrete_scale("colour", "ios_light", ios_light_pal(order = order, accessible = accessible), ...)
}else{
ggplot2::discrete_scale("colour", "ios_accessible_light", ios_light_pal(order = order, accessible = accessible), ...)
}
}
#' @param accessible Indicates whether the accessible set of colors should be
#' used
#' @param order Indicates the order of colors in the palette
#' @rdname scale_colour_ios_light
#' @export
scale_fill_ios_light <- function(order = "contrast", accessible = FALSE, ...) {
if (accessible) {
ggplot2::discrete_scale("fill", "ios_light", ios_light_pal(order = order, accessible = TRUE), ...)
}else{
ggplot2::discrete_scale("fill", "ios_accessible_light", ios_light_pal(order = order, accessible = FALSE), ...)
}
}
#' @param accessible Indicates whether the accessible set of colors should be
#' used
#' @param order Indicates the order of colors in the palette
#' @rdname ios_colour_palettes
#'
#' @examples
#' library(scales)
#' scales::show_col(
#' ios_dark_pal(order = "default", accessible = FALSE)(9),
#' borders = NA, labels = FALSE)
#' scales::show_col(
#' ios_dark_pal(order = "default", accessible = TRUE)(9),
#' borders = NA, labels = FALSE)
#'
#' scales::show_col(
#' ios_dark_pal(order = "contrast", accessible = FALSE)(9),
#' borders = NA, labels = FALSE)
#' scales::show_col(
#' ios_dark_pal(order = "contrast", accessible = TRUE)(9),
#' borders = NA, labels = FALSE)
#'
#' @import scales
#' @export
ios_dark_pal <- function(order = "contrast", accessible = FALSE) {
if (accessible) {
scales::manual_pal(ios_accessible_dark_palette[ios_cols_order[[order]]])
}else{
scales::manual_pal(ios_dark_palette[ios_cols_order[[order]]])
}
}
#' iOS Dark Color Scales
#'
#' @md
#' @description
#' These scales meant to be used with dark themes, e.g, `theme_sf_dark()`.
#' While they can be used with light themes, in general, we recommend pairing
#' `scale_colour_*_dark`s with dark themes for better clarity and contrast.
#'
#' **Note**
#' - *While iOS color palettes provide a total of 9 colors, we do not
#' recommend using them for more than 6 groups. The last three colors often
#' collide with other colors in the palette and may affect the clarity of your
#' visualization.*
#'
#' @param accessible Indicates whether the accessible set of colors should be
#' used
#' @param order Indicates the order of colors in the palette
#'
#' @md
#' @inheritDotParams ggplot2::discrete_scale -expand -position
#' @rdname scale_colour_ios_dark
#' @family colour scales
#'
#' @examples \dontrun{
#'
#' library(ggplot2)
#'
#' ggplot(mtcars, aes(y = mpg, x = as.factor(cyl))) +
#' geom_boxplot(aes(color = as.factor(cyl), fill = as.factor(cyl))) +
#' labs(x = "Miles Per Gallon", y = "MPG",
#' fill = "Number of Cylinders",
#' color = "Number of Cylinders",
#' title = "Fuel Economy",
#' subtitle = "Fuel economy declines as engines gets bigger",
#' caption = "Data from the 1974 Motor Trend US magazine.") +
#' theme_sf_dark() +
#' scale_fill_ios_dark() +
#' scale_colour_ios_dark()
#' }
#' @export
scale_colour_ios_dark <- function(order = "contrast", accessible = FALSE, ...) {
if (accessible) {
ggplot2::discrete_scale("colour", "ios_dark", ios_dark_pal(order = order, accessible = accessible), ...)
}else{
ggplot2::discrete_scale("colour", "ios_accessible_dark", ios_dark_pal(order = order, accessible = accessible), ...)
}
}
#' @param accessible Indicates whether the accessible set of colors should be
#' used
#' @param order Indicates the order of colors in the palette
#' @rdname scale_colour_ios_dark
#' @export
scale_fill_ios_dark <- function(order = "contrast", accessible = FALSE, ...) {
if (accessible) {
ggplot2::discrete_scale("fill", "ios_dark",
ios_dark_pal(order = order,
accessible = TRUE), ...)
}else{
ggplot2::discrete_scale("fill", "ios_accessible_dark",
ios_dark_pal(order = order,
accessible = FALSE), ...)
}
}
# Grays
ios_gray_light_cols <- list(oslo.gray= "#8e8e93",
bombay= "#aeaeb2",
lavender.gray= "#c7c7cc",
light.gray= "#d1d1d6",
white.lilac= "#e5e5ea",
anti.flash.white= "#f2f2f7"
)
ios_gray_light_palette <- unname(unlist(ios_gray_light_cols))
ios_accessible_gray_light_cols <- list(scarpa.flow= "#6c6c70",
oslo.gray= "#8e8e93",
bombay= "#aeaeb2",
french.gray= "#bcbcc0",
alto= "#d8d8dc",
solitude= "#ebebf0")
ios_accessible_gray_light_palette <-
unname(unlist(ios_accessible_gray_light_cols))
ios_gray_dark_cols <- list(oslo.gray= "#8e8e93",
storm.dust= "#636366",
charcoal= "#48484a",
montana= "#3a3a3c",
bunker= "#2c2c2e",
dark.jungle.green= "#1c1c1e")
ios_gray_dark_palette <- unname(unlist(ios_gray_dark_cols))
ios_accessible_gray_dark_cols <- list(bombay= "#aeaeb2",
jumbo= "#7c7c80",
dark.gray= "#545456",
charcoal= "#444446",
shark= "#363638",
nero= "#242426"
)
ios_accessible_gray_dark_palette <-
unname(unlist(ios_accessible_gray_dark_cols))
#' @param accessible Indicates whether the accessible set of colors should be
#' used
#'
#' @rdname ios_colour_palettes
#'
#' @examples
#' library(scales)
#' scales::show_col(
#' ios_gray_light_pal(accessible = FALSE)(6),
#' borders = NA, labels = FALSE)
#' scales::show_col(
#' ios_gray_light_pal(accessible = TRUE)(6),
#' borders = NA, labels = FALSE)
#'
#' @import scales
#' @export
ios_gray_light_pal <- function(accessible = FALSE) {
if (accessible) {
scales::manual_pal(ios_accessible_gray_light_palette)
}else{
scales::manual_pal(ios_gray_light_palette)
}
}
#' iOS Gray Light Color Scales
#'
#' @md
#' @description
#' These scales are based on light gray palette of iOS system colors. They have
#' only been implemented in sfthemes because I wanted to bring all the color
#' palettes mentioned in the Apple's HIG.
#'
#' **Warning**:
#' - *iOS gray colors are not necessary suitable for general
#' plotting; so consider your use-case carefully before adapting them. You can
#' loosely compare them to `ggplot2::scale_alpha()`.*
#'
#' @param accessible Indicates whether the accessible set of colors should be
#' used
#'
#' @md
#' @inheritDotParams ggplot2::discrete_scale -expand -position
#' @rdname scale_colour_ios_gray_light
#' @family colour scales
#'
#' @examples \dontrun{
#'
#' library(ggplot2)
#'
#' ggplot(mtcars, aes(y = mpg, x = as.factor(cyl))) +
#' geom_boxplot(aes(color = as.factor(cyl), fill = as.factor(cyl))) +
#' labs(x = "Miles Per Gallon", y = "MPG",
#' fill = "Number of Cylinders",
#' color = "Number of Cylinders",
#' title = "Fuel Economy",
#' subtitle = "Fuel economy declines as engines gets bigger",
#' caption = "Data from the 1974 Motor Trend US magazine.") +
#' theme_sf_light() +
#' scale_fill_ios_gray_light() +
#' scale_colour_ios_gray_light()
#' }
#' @export
scale_colour_ios_gray_light <- function(accessible = FALSE, ...) {
if (accessible) {
ggplot2::discrete_scale("colour", "ios_gray_light",
ios_gray_light_pal(accessible = TRUE), ...)
}else{
ggplot2::discrete_scale("colour", "ios_accessible_gray_light",
ios_gray_light_pal(accessible = FALSE), ...)
}
}
#'
#' @param accessible Indicates whether the accessible set of colors should be
#' used
#'
#' @rdname scale_colour_ios_gray_light
#'
#' @export
scale_fill_ios_gray_light <- function(accessible = FALSE, ...) {
if (accessible) {
ggplot2::discrete_scale("fill", "ios_gray_light",
ios_gray_light_pal(accessible = TRUE), ...)
}else{
ggplot2::discrete_scale("fill", "ios_accessible_gray_light",
ios_gray_light_pal(accessible = FALSE), ...)
}
}
#' @param accessible Indicates whether the accessible set of colors should be
#' used
#'
#' @rdname ios_colour_palettes
#'
#' @examples
#' library(scales)
#' scales::show_col(
#' ios_gray_dark_pal(accessible = FALSE)(6),
#' borders = NA, labels = FALSE)
#' scales::show_col(
#' ios_gray_dark_pal(accessible = TRUE)(6),
#' borders = NA, labels = FALSE)
#'
#' @import scales
#' @export
ios_gray_dark_pal <- function(accessible = FALSE) {
if (accessible) {
scales::manual_pal(ios_accessible_gray_dark_palette)
}else{
scales::manual_pal(ios_gray_dark_palette)
}
}
#' iOS Gray Dark Color Palette
#'
#' @md
#' @description
#' These scales are based on dark gray palette of iOS system colors. They have
#' only been implemented in sfthemes because I wanted to bring all the color
#' palettes mentioned in the Apple's HIG.
#'
#' **Warning**:
#' - *iOS gray colors are not necessary suitable for general
#' plotting; so consider your use-case carefully before adapting them. You can
#' loosely compare them to `ggplot2::scale_alpha()`.*
#'
#' @param accessible Indicates whether the accessible set of colors should be
#' used
#'
#' @md
#' @inheritDotParams ggplot2::discrete_scale -expand -position
#' @rdname scale_colour_ios_gray_dark
#' @family colour scales
#'
#' @examples \dontrun{
#'
#' library(ggplot2)
#'
#' ggplot(mtcars, aes(y = mpg, x = as.factor(cyl))) +
#' geom_boxplot(aes(color = as.factor(cyl), fill = as.factor(cyl))) +
#' labs(x = "Miles Per Gallon", y = "MPG",
#' fill = "Number of Cylinders",
#' color = "Number of Cylinders",
#' title = "Fuel Economy",
#' subtitle = "Fuel economy declines as engines gets bigger",
#' caption = "Data from the 1974 Motor Trend US magazine.") +
#' theme_sf_dark() +
#' scale_fill_ios_gray_dark() +
#' scale_colour_ios_gray_dark()
#' }
#' @export
scale_colour_ios_gray_dark <- function(accessible = FALSE, ...) {
if (accessible) {
ggplot2::discrete_scale("colour", "ios_gray_dark",
ios_gray_dark_pal(accessible = TRUE), ...)
}else{
ggplot2::discrete_scale("colour", "ios_accessible_gray_dark",
ios_gray_dark_pal(accessible = FALSE), ...)
}
}
#' @param accessible Indicates whether the accessible set of colors should be
#' used
#' @rdname scale_colour_ios_gray_dark
#'
#' @export
scale_fill_ios_gray_dark <- function(accessible = FALSE, ...) {
if (accessible) {
ggplot2::discrete_scale("fill", "ios_gray_dark",
ios_gray_dark_pal(accessible = TRUE), ...)
}else{
ggplot2::discrete_scale("fill", "ios_accessible_gray_dark",
ios_gray_dark_pal(accessible = FALSE), ...)
}
}