Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

color

Set font color


Description

change font color of selected rows and columns of a flextable.

Usage

color(x, i = NULL, j = NULL, color, part = "body", source = j)

Arguments

x

a flextable object

i

rows selection

j

columns selection

color

color to use as font color. If a function, function need to return a character vector of colors.

part

partname of the table (one of 'all', 'body', 'header', 'footer')

source

if bg is a function, source is specifying the dataset column to be used as argument to color. This is only useful if j is colored with values contained in another (or other) column.

Illustrations

See Also

Other sugar functions for table style: align(), bg(), bold(), empty_blanks(), fontsize(), font(), highlight(), italic(), line_spacing(), padding(), rotate(), valign()

Examples

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)

  ft_2 <- flextable(x)
  ft_2 <- color(ft_2, j = x$colname, color = scale)
  ft_2 <- set_formatter_type(ft_2)
  ft_2
}

flextable

Functions for Tabular Reporting

v0.6.10
GPL-3
Authors
David Gohel [aut, cre], Clementine Jager [ctb], Quentin Fazilleau [ctb], Maxim Nazarov [ctb] (rmarkdown for docx output), Titouan Robert [ctb], Michael Barrowman [ctb] (inline footnotes), Atsushi Yasumoto [ctb] (support for bookdown cross reference), Paul Julian [ctb] (support for gam objects)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.