30
30
# ' \code{alpha=TRUE} in which case #RRGGBBAA may also be possible).
31
31
# '
32
32
# ' @export
33
- colorNumeric = function (palette , domain , na.color = " #808080" , alpha = FALSE ) {
33
+ colorNumeric <- function (palette , domain , na.color = " #808080" , alpha = FALSE ) {
34
34
rng = NULL
35
35
if (length(domain ) > 0 ) {
36
36
rng = range(domain , na.rm = TRUE )
@@ -57,14 +57,14 @@ colorNumeric = function(palette, domain, na.color = "#808080", alpha = FALSE) {
57
57
58
58
# Attach an attribute colorType to a color function f so we can derive legend
59
59
# items from it
60
- withColorAttr = function (type , args = list (), fun ) {
60
+ withColorAttr <- function (type , args = list (), fun ) {
61
61
structure(fun , colorType = type , colorArgs = args )
62
62
}
63
63
64
64
# domain may or may not be NULL.
65
65
# Iff domain is non-NULL, x may be NULL.
66
66
# bins is non-NULL. It may be a scalar value (# of breaks) or a set of breaks.
67
- getBins = function (domain , x , bins , pretty ) {
67
+ getBins <- function (domain , x , bins , pretty ) {
68
68
if (is.null(domain ) && is.null(x )) {
69
69
stop(" Assertion failed: domain and x can't both be NULL" )
70
70
}
@@ -97,7 +97,7 @@ getBins = function(domain, x, bins, pretty) {
97
97
# ' to generate the bins and the breaks may not be "pretty".
98
98
# ' @rdname colorNumeric
99
99
# ' @export
100
- colorBin = function (palette , domain , bins = 7 , pretty = TRUE ,
100
+ colorBin <- function (palette , domain , bins = 7 , pretty = TRUE ,
101
101
na.color = " #808080" , alpha = FALSE ) {
102
102
103
103
# domain usually needs to be explicitly provided (even if NULL) but not if
@@ -132,7 +132,7 @@ colorBin = function(palette, domain, bins = 7, pretty = TRUE,
132
132
# ' argument is ignored.
133
133
# ' @rdname colorNumeric
134
134
# ' @export
135
- colorQuantile = function (palette , domain , n = 4 ,
135
+ colorQuantile <- function (palette , domain , n = 4 ,
136
136
probs = seq(0 , 1 , length.out = n + 1 ), na.color = " #808080" , alpha = FALSE ) {
137
137
138
138
if (! is.null(domain )) {
@@ -161,7 +161,7 @@ colorQuantile = function(palette, domain, n = 4,
161
161
162
162
# If already a factor, return the levels. Otherwise, convert to factor then
163
163
# return the levels.
164
- calcLevels = function (x , ordered ) {
164
+ calcLevels <- function (x , ordered ) {
165
165
if (is.null(x )) {
166
166
NULL
167
167
} else if (is.factor(x )) {
@@ -173,7 +173,7 @@ calcLevels = function(x, ordered) {
173
173
}
174
174
}
175
175
176
- getLevels = function (domain , x , lvls , ordered ) {
176
+ getLevels <- function (domain , x , lvls , ordered ) {
177
177
if (! is.null(lvls ))
178
178
return (lvls )
179
179
@@ -195,7 +195,7 @@ getLevels = function(domain, x, lvls, ordered) {
195
195
# ' factor, treat it as already in the correct order
196
196
# ' @rdname colorNumeric
197
197
# ' @export
198
- colorFactor = function (palette , domain , levels = NULL , ordered = FALSE ,
198
+ colorFactor <- function (palette , domain , levels = NULL , ordered = FALSE ,
199
199
na.color = " #808080" , alpha = FALSE ) {
200
200
201
201
# domain usually needs to be explicitly provided (even if NULL) but not if
@@ -268,18 +268,18 @@ colorFactor = function(palette, domain, levels = NULL, ordered = FALSE,
268
268
NULL
269
269
270
270
271
- safePaletteFunc = function (pal , na.color , alpha ) {
271
+ safePaletteFunc <- function (pal , na.color , alpha ) {
272
272
toPaletteFunc(pal , alpha = alpha ) %> % filterRGB() %> % filterZeroLength() %> %
273
273
filterNA(na.color ) %> % filterRange()
274
274
}
275
275
276
- toPaletteFunc = function (pal , alpha ) {
276
+ toPaletteFunc <- function (pal , alpha ) {
277
277
UseMethod(" toPaletteFunc" )
278
278
}
279
279
280
280
# Strings are interpreted as color names, unless length is 1 and it's the name
281
281
# of an RColorBrewer palette
282
- toPaletteFunc.character = function (pal , alpha ) {
282
+ toPaletteFunc.character <- function (pal , alpha ) {
283
283
if (length(pal ) == 1 && pal %in% row.names(RColorBrewer :: brewer.pal.info )) {
284
284
return (scales :: colour_ramp(
285
285
RColorBrewer :: brewer.pal(RColorBrewer :: brewer.pal.info [pal , ' maxcolors' ], pal ),
@@ -291,12 +291,12 @@ toPaletteFunc.character = function(pal, alpha) {
291
291
}
292
292
293
293
# Accept colorRamp style matrix
294
- toPaletteFunc.matrix = function (pal , alpha ) {
294
+ toPaletteFunc.matrix <- function (pal , alpha ) {
295
295
toPaletteFunc(rgb(pal , maxColorValue = 255 ), alpha = alpha )
296
296
}
297
297
298
298
# If a function, just assume it's already a function over [0-1]
299
- toPaletteFunc.function = function (pal , alpha ) {
299
+ toPaletteFunc.function <- function (pal , alpha ) {
300
300
pal
301
301
}
302
302
@@ -306,7 +306,7 @@ toPaletteFunc.function = function(pal, alpha) {
306
306
# ' @param values A set of values to preview colors for
307
307
# ' @return An HTML-based list of the colors and values
308
308
# ' @export
309
- previewColors = function (pal , values ) {
309
+ previewColors <- function (pal , values ) {
310
310
heading = htmltools :: tags $ code(deparse(substitute(pal )))
311
311
subheading = htmltools :: tags $ code(deparse(substitute(values )))
312
312
@@ -336,7 +336,7 @@ previewColors = function(pal, values) {
336
336
337
337
# colorRamp(space = 'Lab') throws error when called with
338
338
# zero-length input
339
- filterZeroLength = function (f ) {
339
+ filterZeroLength <- function (f ) {
340
340
force(f )
341
341
function (x ) {
342
342
if (length(x ) == 0 ) {
@@ -348,7 +348,7 @@ filterZeroLength = function(f) {
348
348
}
349
349
350
350
# Wraps an underlying non-NA-safe function (like colorRamp).
351
- filterNA = function (f , na.color ) {
351
+ filterNA <- function (f , na.color ) {
352
352
force(f )
353
353
function (x ) {
354
354
results = character (length(x ))
@@ -360,7 +360,7 @@ filterNA = function(f, na.color) {
360
360
}
361
361
362
362
# Wraps a function that may return RGB color matrix instead of rgb string.
363
- filterRGB = function (f ) {
363
+ filterRGB <- function (f ) {
364
364
force(f )
365
365
function (x ) {
366
366
results = f(x )
@@ -374,7 +374,7 @@ filterRGB = function(f) {
374
374
}
375
375
}
376
376
377
- filterRange = function (f ) {
377
+ filterRange <- function (f ) {
378
378
force(f )
379
379
function (x ) {
380
380
x [x < 0 | x > 1 ] = NA
0 commit comments