These functions split cell values by quantiles. Non-numeric cells are ignored.

by_quantiles(
quantiles,
values,
right = FALSE,
extend = TRUE,
ignore_na = TRUE,
colwise = FALSE
)

by_equal_groups(n, values, ignore_na = TRUE, colwise = FALSE)

## Arguments

quantiles

Vector of quantiles.

values

Vector of values. length(values) should be one greater than length(quantiles), or one less if extend = FALSE.

right

If TRUE, intervals are closed on the right, i.e. if values are exactly equal to a break, they go in the lower group. Otherwise, intervals are closed on the left, so equal values go in the higher group. FALSE by default.

extend

Extend breaks to c(-Inf, breaks, Inf), i.e. include numbers below and above the outermost breaks. TRUE by default.

ignore_na

If TRUE, NA values in the result will be left unchanged from their previous values. Otherwise, NA normally resets to the default.

colwise

Logical. Calculate breaks separately within each column?

n

Number of equal-sized groups. length(values) should equal n.

## Value

A function for use in map_*** functions.

## Details

by_equal_groups(n, values) splits the data into n equal-sized groups (i.e. it is a shortcut for by_quantiles(seq(1/n, 1 - 1/n, 1/n), values)).

mapping-functions

Other mapping functions: by_cases(), by_colorspace(), by_function(), by_ranges(), by_regex(), by_rows(), by_values()

## Examples

ht <- hux(rnorm(5), rnorm(5))

map_background_color(ht,
by_quantiles(
c(0.2, 0.8),
c("red", "yellow", "green")
))
#>                                -2.21     0.698
#>                                -0.183   -0.0115
#>                                 0.765    1.59
#>                                -1.79    -0.000355
#>                                 1.11    -0.458
#>
#> Column names: c(-2.20943627927108, -0.183158158601004, 0.764610362621447,
#> -1.79477957813802, , c(0.698274452339709, -0.0115295922476895,
#> 1.59339880295194, -0.000354854823912664,

map_background_color(ht,
by_quantiles(
c(0.2, 0.8),
c("red", "yellow", "green"),
colwise = TRUE
))
#>                                -2.21     0.698
#>                                -0.183   -0.0115
#>                                 0.765    1.59
#>                                -1.79    -0.000355
#>                                 1.11    -0.458
#>
#> Column names: c(-2.20943627927108, -0.183158158601004, 0.764610362621447,
#> -1.79477957813802, , c(0.698274452339709, -0.0115295922476895,
#> 1.59339880295194, -0.000354854823912664,

map_background_color(ht,
by_equal_groups(
3,
c("red", "yellow", "green")
))
#>                                -2.21     0.698
#>                                -0.183   -0.0115
#>                                 0.765    1.59
#>                                -1.79    -0.000355
#>                                 1.11    -0.458
#>
#> Column names: c(-2.20943627927108, -0.183158158601004, 0.764610362621447,
#> -1.79477957813802, , c(0.698274452339709, -0.0115295922476895,
#> 1.59339880295194, -0.000354854823912664,