1

I've used the formattable package to create conditional formatting of the cells using two colors (see below). I want to however use three colors (red, yellow, green) but am not sure of how to do that. Or perhaps even a spectrum of colors (using RColorBrewer).

library(tidyverse) 
library(kableExtra)
library(formattable) 

mtcars[1:5, 1:4] %>% 
  mutate(car = row.names(.)) %>% 
  select(car, everything()) %>% 
  arrange(-mpg) %>% 
  mutate(mpg = color_tile("red", "green")(mpg)) %>% 
  kable(escape = F) %>%
  kable_styling("hover", full_width = F) 

enter image description here

Greg Martin
  • 243
  • 3
  • 5
  • 17

0 Answers0