by_ranges: Map numeric ranges to cell properties

Description Usage Arguments Details Value See Also Examples

Description

by_ranges() sets property values for cells falling within different numeric ranges.

Usage

1
by_ranges(breaks, values, right = FALSE, extend = TRUE, ignore_na = TRUE)

Arguments

breaks

A vector of numbers in increasing order.

values

A vector of property values. length(values) should be one greater than length(breaks) if extend = TRUE, 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.

Details

Non-numeric cells return NA. The effects of this depend on ignore_na.

Value

A function for use in map_*** functions.

See Also

mapping-functions

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
ht <- huxtable(c(1, 3, 5))
map_background_color(ht,
      by_ranges(
        c(2, 4),
        c("red", "yellow", "blue")
      ))

map_background_color(ht,
      by_ranges(
        c(2, 4),
        "pink",
        extend = FALSE
      ))

map_background_color(ht,
      by_ranges(
        c(1, 5),
        c("red", "yellow", "green"),
        right = TRUE
      ))
map_background_color(ht,
      by_ranges(
        c(1, 5),
        c("red", "yellow", "green"),
        right = FALSE
      ))

Example output

                                              1  
                                              3  
                                              5  

Column names: c(1, 3, 5)
                                              1  
                                              3  
                                              5  

Column names: c(1, 3, 5)
                                              1  
                                              3  
                                              5  

Column names: c(1, 3, 5)
                                              1  
                                              3  
                                              5  

Column names: c(1, 3, 5)

huxtable documentation built on May 15, 2021, 1:09 a.m.