This question is related to this one: How can I color the same value in the same color in the entire gt table in R?
Basically the OP asks to change the font color in an gt object conditionally:
if value == 4 -> font blue if value == 0 -> font red
It turned out that it is not as easy as I thought. I managed to change the colors in specific columns like:
library(gt)
library(dplyr)
mtcars %>%
gt() %>%
tab_style(
style = cell_text(color = "red", weight = "bold"),
locations = cells_body(
columns = am,
rows = am == 0
)
) %>%
tab_style(
style = cell_text(color = "blue", weight = "bold"),
locations = cells_body(
columns = cyl,
rows = cyl == 4
)
)
My question: How can I modify my code to apply these condition to all columns!
e.g all 0
are red and all 4
are blue!