This function uses dplyr::case_when()
to set cell properties.
by_cases(..., ignore_na = TRUE)
... | A list of two-sided formulas interpreted by |
---|---|
ignore_na | If |
A function for use in map_***
functions.
Within the formulas, the variable .
will refer to the content of
ht[rows, cols]
, after conversion by as.matrix()
.
case_when
returns NA
when no formula LHS is matched. To avoid this, set a
default in the last formula: TRUE ~ default
.
case_when
can't deal with brdr()
objects, so you cannot use
these in by_cases()
.
Other mapping functions:
by_colorspace()
,
by_function()
,
by_quantiles()
,
by_ranges()
,
by_regex()
,
by_rows()
,
by_values()
if (! requireNamespace("dplyr")) { stop("Please install the 'dplyr' package to run this example") } ht <- hux(runif(5), letters[1:5]) map_background_color(ht, by_cases( . == "a" ~ "red", . %in% letters ~ "green", . < 0.5 ~ "pink" ))#> 0.29 a #> 0.678 b #> 0.735 c #> 0.196 d #> 0.981 e #> #> Column names: c(0.289892295375466, 0.678380427416414, 0.735319598810747, #> 0.195956733077765, , c("a", "b", "c", "d", "e")