1

I am creating tables using flextable and officer. I would like to apply conditional formatting to cells, e.g., if a value is > 1.5, apply a colored background. I understand how to color entire rows or columns but not individual cells. Is this possible?

  • 1
    Take a look at the `conditional formatting` section of flextable vignette https://cran.r-project.org/web/packages/flextable/vignettes/format.html – R.S. Oct 25 '20 at 19:27

1 Answers1

2

Using the airquality dataset to demonstrate conditional formatting of cell :

library(flextable)

#https://cran.r-project.org/web/packages/flextable/vignettes/format.html
df<- datasets::airquality
ft<- flextable(df)
ft<- bg(ft, bg = "#E4C994", part = "header")
ft<- bg( ft, bg = "#99CCFF", part = "body")
#conditional formatting : 
#i is row , conditional . j is column 
bg(ft, i = ~ Temp>70, 
      j = ~ Temp, 
      bg="red")

The result would be :

enter image description here

R.S.
  • 2,093
  • 14
  • 29