Tiled formats using formatted in R

I would like to use color_tile

in a calculation based column instead of basing it on its own continuous scale. I have some code to format the text color in the following example:

library(formattable)

my.df <- data.frame(
   Type = c("A", "B", "C", "D", "E"),
   Count = c(5, 7, 3, 8, 4),
   Expect = c(2, 6, 3, 15, 0)
 )

formattable(my.df, list(
  Type = formatter("span",
                   style = ~style(color = ifelse(Count/Expect - 1 > .2, "red", 
    ifelse(Count/Expect - 1 < -.2, "green", "black")))
                   )

  ))

      

These are the colors I want, but instead of colored text, I would like to have tiles. I have not figured out how I can use color_tile

which is calculation based or based on something other than its own column values. Can I use tiles?

+3


source to share





All Articles