% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/styles.R
\name{color}
\alias{color}
\title{Set font color}
\usage{
color(x, i = NULL, j = NULL, color, part = "body", source = j)
}
\arguments{
\item{x}{a 'flextable' object, see \link{flextable-package} to learn how to create
'flextable' object.}

\item{i}{row selector, see section \emph{Row selection with the \code{i} parameter}
in <\code{\link[=flextable_selectors]{Selectors in flextable}}>.}

\item{j}{column selector, see section \emph{Column selection with the \code{j} parameter}
in <\code{\link[=flextable_selectors]{Selectors in flextable}}>.}

\item{color}{color to use as font color. If a function, the function must return
a character vector of colors.}

\item{part}{part selector, see section \emph{Part selection with the \code{part}
parameter} in <\code{\link[=flextable_selectors]{Selectors in flextable}}>.
Value 'all' can be used.}

\item{source}{if color is a function, source specifies the dataset column to be used
as an argument to \code{color}. This is only useful when j is colored with values contained in
other columns.}
}
\description{
Change the text color of selected rows and
columns of a flextable. A function can be used instead of
fixed colors.

When \code{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 \code{colkeys}) is a common use case. The argument \code{source}
must be used to define the columns to be used for the color
definition, and the argument \code{j} must be used to define where to apply
the colors and only accepts values from \code{colkeys}.
}
\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
  )
}
}
\seealso{
Other formatting shortcuts:
\code{\link[=align]{align()}},
\code{\link[=bg]{bg()}},
\code{\link[=bold]{bold()}},
\code{\link[=empty_blanks]{empty_blanks()}},
\code{\link[=font]{font()}},
\code{\link[=fontsize]{fontsize()}},
\code{\link[=highlight]{highlight()}},
\code{\link[=indentation]{indentation()}},
\code{\link[=italic]{italic()}},
\code{\link[=keep_with_next]{keep_with_next()}},
\code{\link[=line_spacing]{line_spacing()}},
\code{\link[=padding]{padding()}},
\code{\link[=rotate]{rotate()}},
\code{\link[=style]{style()}},
\code{\link[=tab_settings]{tab_settings()}},
\code{\link[=valign]{valign()}}
}
\concept{formatting_shortcuts}
