我正在使用 formattable:color_bar 格式化表格,并想添加一个逗号作为千位分隔符以及调整字体的颜色。
对于我不使用 color_bar 的单元格,我了解如何使用 cell_spec 更改字体颜色,但我不知道如何处理使用 color_bar 的单元格。
library(tidyverse)
library(knitr)
library(kableExtra)
library(formattable)
df <- tibble (
rank = c(1,2,3),
tree = c("Norway Maple", "Honey Locust", "Colorado Blue Spruce"),
number = c(74688, 24286, 21917)
)
df %>%
mutate(
tree = cell_spec(tree, "html", color = "black"),
number = color_bar()(number)) %>%
kable("html", escape = F, align = c("l", "l")) %>%
kable_styling(bootstrap_options = c("hover", "responsive", "condensed"), full_width = F, position = "float_left") %>%
column_spec(3, width = "10cm")