【发布时间】:2019-11-29 23:51:31
【问题描述】:
是否可以通过不同的表格中给出的颜色对表格(使用 huxtable 生成)进行颜色编码?
head_mtcars <- head(mtcars)
tbl_A <- as_hux(head_mtcars[1:2])
tbl_B <- as_hux(head_mtcars[3:4])
1) 首先,我想分别为tbl_A 的第 1 列和第 2 列中的元素着色,分别为每一列的颜色空间
tbl_A %>%
huxtable::add_colnames() %>%
map_background_color("for each column of tbl_A", by_colorspace("orange", "white", "green"))
2) 接下来,我想为tbl_A 的第 1 列和第 2 列中的元素通过 tbl_B 的每一列的颜色空间着色,
即tbl_B[,1] 表tbl_A 的col 1 中的元素和tbl_B[,2] 表tbl_A 的col 2 中的元素
tbl_A %>%
huxtable::add_colnames() %>%
map_background_color("for each column of tbl_B", by_colorspace("orange", "white", "green"))
3) 最后,不是按列,而是按整个表格:根据 ht2 的值对 ht 中的元素着色:
ht <- as_hux(matrix(rnorm(25), 5, 5))
ht2 <- as_hux(matrix(rnorm(25), 5, 5))
map_background_color(ht, by_colorspace("orange", "white", "green"))
非常感谢您的帮助!
【问题讨论】:
-
你是致力于huxtable,还是可以考虑其他的table方法?这是使用 flextable 的一种解决方案:stackoverflow.com/questions/58677080/…
标签: r