1
1
# ' Flat UI color palette
2
2
# '
3
- # ' The palette based on [Flat UI](https://materialui.co/flatuicolors).
4
- # ' Use `scale_color_flat_d` for *discrete* categories and
5
- # ' `scale_color_flat_c` for a *continuous* scale.
3
+ # ' The palette based on [Flat UI](https://materialui.co/flatuicolors). Use
4
+ # ' `scale_color_flat_d` for *discrete* categories and `scale_color_flat_c` for a
5
+ # ' *continuous* scale, or use the `discrete` argument in `scale_color_flat()` .
6
6
# '
7
7
# ' @inheritParams palette_flat
8
8
# ' @param discrete Boolean indicating whether color aesthetic is discrete or not.
18
18
# ' ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
19
19
# ' geom_boxplot() +
20
20
# ' theme_modern() +
21
- # ' scale_fill_flat_d ()
21
+ # ' scale_fill_flat ()
22
22
# '
23
23
# ' ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
24
24
# ' geom_violin() +
25
25
# ' theme_modern() +
26
- # ' scale_fill_flat_d (palette = "ice")
26
+ # ' scale_fill_flat (palette = "ice")
27
27
# '
28
28
# ' ggplot(iris, aes(x = Petal.Length, y = Petal.Width, color = Sepal.Length)) +
29
29
# ' geom_point() +
30
30
# ' theme_modern() +
31
- # ' scale_color_flat_c(palette = "rainbow" )
31
+ # ' scale_color_flat(discrete = FALSE )
32
32
# ' @export
33
- scale_color_flat <- function (palette = " contrast " ,
33
+ scale_color_flat <- function (palette = NULL ,
34
34
discrete = TRUE ,
35
35
reverse = FALSE ,
36
36
aesthetics = " color" ,
37
37
... ) {
38
+ if (is.null(palette )) {
39
+ if (discrete ) {
40
+ palette <- " contrast"
41
+ } else {
42
+ palette <- " gradient"
43
+ }
44
+ }
45
+
38
46
pal <- palette_flat(palette = palette , reverse = reverse )
39
47
40
48
if (discrete ) {
@@ -50,7 +58,7 @@ scale_color_flat <- function(palette = "contrast",
50
58
51
59
# ' @rdname scale_color_flat
52
60
# ' @export
53
- scale_color_flat_d <- function (palette = " contrast " ,
61
+ scale_color_flat_d <- function (palette = NULL ,
54
62
discrete = TRUE ,
55
63
reverse = FALSE ,
56
64
aesthetics = " color" ,
@@ -66,7 +74,7 @@ scale_color_flat_d <- function(palette = "contrast",
66
74
67
75
# ' @rdname scale_color_flat
68
76
# ' @export
69
- scale_color_flat_c <- function (palette = " contrast " ,
77
+ scale_color_flat_c <- function (palette = NULL ,
70
78
discrete = FALSE ,
71
79
reverse = FALSE ,
72
80
aesthetics = " color" ,
@@ -98,11 +106,19 @@ scale_colour_flat_d <- scale_color_flat_d
98
106
99
107
# ' @rdname scale_color_flat
100
108
# ' @export
101
- scale_fill_flat <- function (palette = " contrast " ,
109
+ scale_fill_flat <- function (palette = NULL ,
102
110
discrete = TRUE ,
103
111
reverse = FALSE ,
104
112
aesthetics = " fill" ,
105
113
... ) {
114
+ if (is.null(palette )) {
115
+ if (discrete ) {
116
+ palette <- " contrast"
117
+ } else {
118
+ palette <- " gradient"
119
+ }
120
+ }
121
+
106
122
pal <- palette_flat(palette = palette , reverse = reverse )
107
123
108
124
if (discrete ) {
@@ -115,7 +131,7 @@ scale_fill_flat <- function(palette = "contrast",
115
131
116
132
# ' @rdname scale_color_flat
117
133
# ' @export
118
- scale_fill_flat_d <- function (palette = " contrast " ,
134
+ scale_fill_flat_d <- function (palette = NULL ,
119
135
discrete = TRUE ,
120
136
reverse = FALSE ,
121
137
aesthetics = " fill" ,
@@ -131,7 +147,7 @@ scale_fill_flat_d <- function(palette = "contrast",
131
147
132
148
# ' @rdname scale_color_flat
133
149
# ' @export
134
- scale_fill_flat_c <- function (palette = " contrast " ,
150
+ scale_fill_flat_c <- function (palette = NULL ,
135
151
discrete = FALSE ,
136
152
reverse = FALSE ,
137
153
aesthetics = " fill" ,
@@ -151,21 +167,21 @@ scale_fill_flat_c <- function(palette = "contrast",
151
167
152
168
# The palette based on flat design colors: https://www.materialui.co/flatuicolors
153
169
flat_colors_list <- c(
154
- ` red` = " #e74c3c" ,
170
+ red = " #e74c3c" ,
155
171
`dark red` = " #c0392b" ,
156
- ` purple` = " #9b59b6" ,
172
+ purple = " #9b59b6" ,
157
173
`deep purple` = " #8e44ad" ,
158
- ` blue` = " #2980b9" ,
174
+ blue = " #2980b9" ,
159
175
`light blue` = " #3498db" ,
160
- ` cyan` = " #1abc9c" ,
161
- ` teal` = " #16a085" ,
162
- ` green` = " #27ae60" ,
176
+ cyan = " #1abc9c" ,
177
+ teal = " #16a085" ,
178
+ green = " #27ae60" ,
163
179
`light green` = " #2ecc71" ,
164
- ` yellow` = " #f1c40f" ,
165
- ` amber` = " #f39c12" ,
166
- ` orange` = " #e67e22" ,
180
+ yellow = " #f1c40f" ,
181
+ amber = " #f39c12" ,
182
+ orange = " #e67e22" ,
167
183
`deep orange` = " #d35400" ,
168
- ` grey` = " #95a5a6" ,
184
+ grey = " #95a5a6" ,
169
185
`blue grey` = " #7f8c8d"
170
186
)
171
187
@@ -196,9 +212,10 @@ flat_colors <- function(...) {
196
212
197
213
198
214
flat_palettes <- list (
199
- `full` = flat_colors(),
200
- `ice` = flat_colors(" purple" , " deep purple" , " blue" , " light blue" ),
201
- `rainbow` = flat_colors(
215
+ full = flat_colors(),
216
+ ice = flat_colors(" purple" , " deep purple" , " blue" , " light blue" ),
217
+ gradient = flat_colors(" blue" , " orange" ),
218
+ rainbow = flat_colors(
202
219
" purple" ,
203
220
" deep purple" ,
204
221
" blue" ,
@@ -210,9 +227,9 @@ flat_palettes <- list(
210
227
" deep orange" ,
211
228
" red"
212
229
),
213
- ` contrast` = flat_colors(" blue" , " green" , " amber" , " purple" , " red" ),
214
- ` light` = flat_colors(" light blue" , " purple" , " yellow" , " light green" , " orange" ),
215
- ` complement` = flat_colors(
230
+ contrast = flat_colors(" blue" , " green" , " amber" , " purple" , " red" ),
231
+ light = flat_colors(" light blue" , " purple" , " yellow" , " light green" , " orange" ),
232
+ complement = flat_colors(
216
233
" blue grey" ,
217
234
" blue" ,
218
235
" light blue" ,
@@ -231,9 +248,13 @@ flat_palettes <- list(
231
248
# ' The palette based on [Flat UI](https://materialui.co/flatuicolors).
232
249
# '
233
250
# ' @param palette Character name of palette. Depending on the color scale, can
234
- # ' be `"full"`, `"ice"`, `"rainbow"`, `"complement"`,
235
- # ' `"contrast"`, `"light"` (for dark themes), `"black_first"`, `full_original`,
236
- # ' or `black_first_original`.
251
+ # ' be one of `"full"`, `"ice"`, `"rainbow"`, `"complement"`, `"contrast"`,
252
+ # ' `"light"` (for dark themes), `"black_first"`, `full_original`, or
253
+ # ' `black_first_original`. The latter three options are especially for the
254
+ # ' Okabe-Ito color palette. The default is `NULL` and either `"contrast"` or
255
+ # ' `"gradient"` is used (depending on whether `discrete` is `TRUE` or `FALSE`),
256
+ # ' which are the two scale useful for discrete or gradient color scales,
257
+ # ' respectively.
237
258
# ' @param reverse Boolean indicating whether the palette should be reversed.
238
259
# ' @param ... Additional arguments to pass to [`colorRampPalette()`][colorRampPalette].
239
260
# '
0 commit comments