
change text highlight color of selected rows and columns of a flextable.
highlight(x, i = NULL, j = NULL, color = "yellow", part = "body", source = j)
a flextable object
rows selection
columns selection
color to use as text highlighting color. If a function, function need to return a character vector of colors.
partname of the table (one of 'all', 'body', 'header', 'footer')
if color 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.
Other sugar functions for table style:
align()
,
bg()
,
bold()
,
color()
,
empty_blanks()
,
fontsize()
,
font()
,
italic()
,
line_spacing()
,
padding()
,
rotate()
,
valign()
# NOT RUN {
my_color_fun <- function(x){
out <- rep("yellow", length(x))
out[x < quantile(x, .75)] <- "pink"
out[x < quantile(x, .50)] <- "wheat"
out[x < quantile(x, .25)] <- "gray90"
out
}
ft <- flextable(head( mtcars, n = 10))
ft <- highlight(ft, j = "disp", i = ~ disp > 200, color = "yellow")
ft <- highlight(ft, j = ~ drat + wt + qsec, color = my_color_fun)
ft
# }
Run the code above in your browser using DataLab