I would like to color specific cells in the following dataframe. For example, in the inputval column, I would like to highlight cells in the range of [0.8, 0.9)
magenta, and the cells in that same column in the range of [0.7, 0.8)
blue. Similarly, I'd like the output column cells with a value of 1 to be colored magenta and those with value 4 to be colored blue. For the rest of the cells in the dataframe, I would like them to remain white.
I have the following reproducible code which highlights by row only, and limits me to coloring in magenta and white only. How can I add another color and do so by cell?
set.seed(123)
df <- data.frame(id = sample(1:100, 20, replace = TRUE),
inputval = sample(seq(0, 1, by=0.01), 20, replace = TRUE),
outcome = sample(1:4, 20, replace = TRUE))
cols <- with(df, ifelse(outcome == 1, 'magenta', 'white'))
library('htmlTable')
htmlTable(as.matrix(df), col.rgroup = cols)
I realize that the issue for adding different colors is with the ifelse
call in with
that limits me to just magenta and white. How can I add another condition here?
While I know what's causing the multiple color issue, I'm pretty clueless about how to color only specific cells.
This is the same example as the accepted answer to this question.
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…