by_colorspace()
can be used to set background, border or
text colors, visually differentiating high or low values.
by_colorspace(
...,
range = NULL,
na_color = NA,
ignore_na = TRUE,
colwise = FALSE
)
Colors
Numeric endpoints. If NULL
, these are determined from the data.
Color to return for NA
values. Can be NA
itself.
If TRUE
, NA
values in the result will be left unchanged
from their previous values. Otherwise, NA
normally resets to the default.
Logical. Calculate breaks separately within each column?
A function for use in map_***
functions.
by_colorspace
requires the "scales" package.
Other mapping functions:
by_cases()
,
by_function()
,
by_quantiles()
,
by_ranges()
,
by_regex()
,
by_rows()
,
by_values()
if (! requireNamespace("scales")) {
stop("Please install the \"scales\" package to run this example")
}
ht <- as_hux(matrix(rnorm(25), 5, 5))
map_background_color(ht,
by_colorspace("red", "yellow", "blue"))
#> 0.648 -0.171 0.724 0.77 -0.872
#> 0.0758 1.63 2.35 0.563 0.107
#> 0.492 -0.783 -0.281 -0.374 -0.587
#> -0.754 -0.00289 -0.481 -0.601 -0.328
#> 0.349 0.413 0.0792 -0.424 -0.0854
#>
#> Column names: V1, V2, V3, V4, V5
map_background_color(ht,
by_colorspace("red", "yellow", "blue",
colwise = TRUE))
#> 0.648 -0.171 0.724 0.77 -0.872
#> 0.0758 1.63 2.35 0.563 0.107
#> 0.492 -0.783 -0.281 -0.374 -0.587
#> -0.754 -0.00289 -0.481 -0.601 -0.328
#> 0.349 0.413 0.0792 -0.424 -0.0854
#>
#> Column names: V1, V2, V3, V4, V5