by_colorspace() can be used to set background, border or
text colors, visually differentiating high or low values.
Arguments
- ...
Colors
- range
Numeric endpoints. If
NULL, these are determined from the data.- na_color
Color to return for
NAvalues. Can beNAitself.- ignore_na
If
TRUE,NAvalues in the result will be left unchanged from their previous values. Otherwise,NAnormally resets to the default.- colwise
Logical. Calculate breaks separately within each column?
See also
Other mapping functions:
by_cases(),
by_function(),
by_quantiles(),
by_ranges(),
by_regex(),
by_rows(),
by_values()
Examples
if (!requireNamespace("scales")) {
stop("Please install the \"scales\" package to run this example")
}
#> Loading required namespace: scales
ht <- as_hux(matrix(rnorm(25), 5, 5))
map_background_color(
ht,
by_colorspace("red", "yellow", "blue")
)
#> 0.563 0.107 0.151 -0.795 0.973
#> -0.374 -0.587 -0.293 -1.57 -0.0768
#> -0.601 -0.328 0.255 -1.04 0.893
#> -0.424 -0.0854 -0.553 1.02 -0.778
#> -0.872 -2.05 1.41 -0.702 0.437
#>
#> Column names: V1, V2, V3, V4, V5
map_background_color(
ht,
by_colorspace("red", "yellow", "blue",
colwise = TRUE
)
)
#> 0.563 0.107 0.151 -0.795 0.973
#> -0.374 -0.587 -0.293 -1.57 -0.0768
#> -0.601 -0.328 0.255 -1.04 0.893
#> -0.424 -0.0854 -0.553 1.02 -0.778
#> -0.872 -2.05 1.41 -0.702 0.437
#>
#> Column names: V1, V2, V3, V4, V5