| color | R Documentation |
Change the text color of selected rows and columns of a flextable. A function can be used instead of fixed colors.
When color is a function, it is possible to color cells based on values
located in other columns; using hidden columns (those not used by
argument colkeys) is a common use case. The argument source
must be used to define the columns to be used for the color
definition, and the argument j must be used to define where to apply
the colors and only accepts values from colkeys.
color(x, i = NULL, j = NULL, color, part = "body", source = j)
x |
a 'flextable' object, see flextable-package to learn how to create 'flextable' object. |
i |
row selector, see section Row selection with the |
j |
column selector, see section Column selection with the |
color |
color to use as font color. If a function, the function must return a character vector of colors. |
part |
part selector, see section Part selection with the |
source |
if color is a function, source specifies the dataset column to be used
as an argument to |
Other formatting shortcuts:
align(),
bg(),
bold(),
empty_blanks(),
font(),
fontsize(),
highlight(),
italic(),
keep_with_next(),
line_spacing(),
padding(),
rotate(),
style(),
tab_settings(),
valign()
ft <- flextable(head(mtcars))
ft <- color(ft, color = "orange", part = "header")
ft <- color(ft,
color = "red",
i = ~ qsec < 18 & vs < 1
)
ft
if (require("scales")) {
scale <- scales::col_numeric(domain = c(-1, 1), palette = "RdBu")
x <- as.data.frame(cor(iris[-5]))
x <- cbind(
data.frame(
colname = colnames(x),
stringsAsFactors = FALSE
),
x
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.