I am maintaining a Rmarkdown report which contains a summary table for monthly performance rolling 12 months. The management would like to have color coding to indicate the performance against the target. I am trying to accomplish this with R formattable package. The issue i am having now is that the column names might change month from month(since i am using rolling 12 months), below is the sample data:
library(tidyverse)
library(formattable)
sample_data <- tibble(
Country=c("CHINA","JAPAN"),
`19-01`=c(95,94),
`19-02`=c(97,93),
`19-03`=c(95,98),
`19-04`=c(85,96),
`19-05`=c(95,94),
`19-06`=c(97,93),
`19-07`=c(95,98),
`19-08`=c(85,96),
`19-09`=c(95,94),
`19-10`=c(97,93),
`19-11`=c(95,98),
`19-12`=c(85,96),
`Year to Date`=c(95,98))
What I am trying to achieve is that, for every month (as well as the last column of Year to Date
), if the performance is below 95, the background color is set to RED, if the performance is between 95 and 96, the cell background is set to YELLOW and if the performance is above 96, the background color is set to GREEN.
How can i achieve this even though the column names would be changed next month?
Thanks for your help.
Felix