R/rule_fill_bar.R
rule_fill_bar.RdFills the background of a column cell using a bar proportional to the value of the cell
rule_fill_bar(
x,
columns,
expression,
low = "darkgreen",
high = "white",
background = "white",
na.value = "gray",
limits = NA,
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 numeric vector,
that will be used to determine the colour gradient level.
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 (and limits, if not given, computed from
that column alone). If omitted, it defaults to .col.
Colour for the beginning of the bar
Colour for the end of the bar
Background colour for the cell
Colour for missing values
range of limits that the gradient should cover
logical value determining if no further rules should be applied to the affected cells.
The condformat_tbl object, with the added formatting information
In Excel output (condformat2excel()/condformat2excelsheet()), this is
rendered using Excel's own native data bar conditional formatting, coloured
with low (high, background and lockcells don't apply to it, since
Excel data bars are solid-coloured and are a workbook-level conditional
formatting rule, not a per-cell style). This only happens when expression
is left at its default (or explicitly .col): Excel data bars always
reflect a cell's own displayed value against a range, so a custom
expression (e.g. sizing one column's bar by another column's values)
can't be replicated there and is skipped, with a warning; the cell's flat
background/na.value colours are still applied in that case.
data(iris)
cf <- condformat(iris[c(1:5, 70:75, 120:125), ]) |> rule_fill_bar("Sepal.Length")
if (FALSE) { # \dontrun{
print(cf)
} # }