Conditional formatting of multiple columns in gt table

mtcars %>% 
  as_tibble() %>% 
  select(mpg, cyl, disp) %>%  
  head(5) %>% 
  gt() %>% 

  tab_style(
    style = cell_fill(color = "red"),
    locations = cells_body(
      columns = vars(disp),
      rows = disp > mean(disp)
    )
  ) %>% 
  tab_style(
    style = cell_fill(color = "red"),
    locations = cells_body(
      columns = vars(cyl),
      rows = cyl > mean(cyl)
    )
  ) %>% 
  tab_style(
    style = cell_fill(color = "red"),
    locations = cells_body(
      columns = vars(mpg),
      rows = mpg > mean(mpg)
    )
  )

I want to know if there be a better way to get to my goal, instead of repeating the 'style_tab()' tailored to each column. Help?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.