Map cell contents to cell properties using a function or scale
Source:R/mapping-functions.R
by_function.RdThis creates a simple wrapper around a function for use in map_xxx.
Useful functions include scales and palettes from the scales package.
Details
The argument of inner_fn will be as.matrix(ht[row, col]). Be aware how matrix conversion
affects the mode of cell data.
See also
Other mapping functions:
by_cases(),
by_colorspace(),
by_quantiles(),
by_ranges(),
by_regex(),
by_rows(),
by_values()
Examples
ht <- as_hux(matrix(runif(20), 5, 4))
map_background_color(
ht,
by_function(grey)
)
#> 0.836 0.996 0.634 0.867
#> 0.709 0.5 0.859 0.249
#> 0.874 0.359 0.567 0.403
#> 0.0115 0.775 0.253 0.77
#> 0.888 0.584 0.919 0.119
#>
#> Column names: V1, V2, V3, V4
if (requireNamespace("scales")) {
map_text_color(ht, by_function(
scales::seq_gradient_pal()
))
}
#> 0.836 0.996 0.634 0.867
#> 0.709 0.5 0.859 0.249
#> 0.874 0.359 0.567 0.403
#> 0.0115 0.775 0.253 0.77
#> 0.888 0.584 0.919 0.119
#>
#> Column names: V1, V2, V3, V4