Fills a column or columns of a data frame using a discrete colour palette, based on an expression.
rule_fill_discrete(
x,
columns,
expression,
colours = NA,
na.value = "#FFFFFF",
h = c(0, 360) + 15,
c = 100,
l = 65,
h.start = 0,
direction = 1,
lockcells = FALSE
)A condformat object, typically created with condformat()
A character vector with column names to be coloured. Optionally
tidyselect::language() can be used.
an expression to be evaluated with the data.
It should evaluate to a logical or an integer vector,
that will be used to determine which cells are to be coloured.
When columns selects more than one column, the expression is
evaluated once per column, with the .col pronoun bound to that
column's own values, so the same call can colour several columns
based on each one's own condition. If omitted, it defaults to .col.
a character vector with colours as values and the expression possible results as names.
a character string with the CSS color to be used in missing values
range of hues to use, in [0, 360]
chroma (intensity of colour), maximum value varies depending on combination of hue and luminance.
luminance (lightness), in [0, 100]
hue to start at
direction to travel around the colour wheel, 1 = clockwise, -1 = counter-clockwise
logical value determining if no further rules should be applied to the affected cells.
The condformat_tbl object, with the added formatting information
data(iris)
cf <- condformat(iris[c(1:5, 70:75, 120:125), ]) |>
rule_fill_discrete("Species", colours = c("setosa" = "red",
"versicolor" = "blue",
"virginica" = "green")) |>
rule_fill_discrete("Sepal.Length", expression = Sepal.Length > 4.6,
colours=c("TRUE"="red"))
if (FALSE) { # \dontrun{
print(cf)
} # }
cf <- condformat(iris[c(1:5, 70:75, 120:125), ]) |>
rule_fill_discrete(c(starts_with("Sepal"), starts_with("Petal")),
expression = Sepal.Length > 4.6,
colours=c("TRUE"="red"))
if (FALSE) { # \dontrun{
print(cf)
} # }
# .col lets each selected column use its own values in the expression:
cf <- condformat(iris[c(1:5, 70:75, 120:125), ]) |>
rule_fill_discrete(c(Sepal.Length, Sepal.Width), .col > 3,
colours = c("TRUE" = "red"))
if (FALSE) { # \dontrun{
print(cf)
} # }