I have some categorical values I want to show in a table as red, yellow and green spots in R or r-markdown.
Is there a way to do this? maybe an icon package that will l
Here's an example that uses html format in knitr. It uses the cell_spec
function to make a new column using an icon and colour.
library(kableExtra)
library(emojifont)
library(dplyr)
load.fontawesome()
options(knitr.table.format = 'html')
cylcols = function(cyl) {
case_when(
cyl == 4 ~ 'green',
cyl == 6 ~ 'yellow',
cyl == 8 ~ 'red'
)
}
dt <-
mtcars[1:5, 1:6] %>%
mutate(symbol = fontawesome('fa-circle')) %>%
mutate(symbol = cell_spec(symbol, 'html', color=cylcols(cyl))) %>%
select(mpg, cyl=symbol, disp, hp, drat, wt)
kable(dt, escape = F) %>%
kable_styling(full_width = F, font_size = 12) %>%
row_spec(0, angle = -90) %>%
row_spec(1:5, bold = F, color = "black")