R Huxtable:用另一个矩阵对矩阵进行颜色编码

R Huxtable:用另一个矩阵对矩阵进行颜色编码,r,R,是否可以通过不同表中给定的颜色对表(使用huxtable生成)进行颜色编码 2) 接下来,我想用tbl_B的每一列的颜色空间对tbl_A的第1列和第2列中的元素着色, i、 例如,表tbl_Abytbl_B[,1]第1列中的元素和表tbl_Abytbl_B[,2] tbl_A %>% huxtable::add_colnames() %>% map_background_color("for each column of tbl_B", by_colorspace("oran

是否可以通过不同表中给定的颜色对表(使用huxtable生成)进行颜色编码

2) 接下来,我想用tbl_B的每一列的颜色空间对
tbl_A
的第1列和第2列中的元素着色, i、 例如,表
tbl_A
by
tbl_B[,1]
第1列中的元素和表
tbl_A
by
tbl_B[,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"))

htA部分:要按列应用颜色空间,必须单独指定它们:

tbl_A %>% 
  map_background_color(everywhere, 1, by_colorspace("orange", "white", "green")) %>%
  map_background_color(everywhere, 2, by_colorspace("orange", "white", "green")) %>%
  huxtable::add_colnames() 
这可能是一个特性请求,因为我可以想象按列进行是一个常见的用例

第二部分:我认为“手动”将是最简单的——即,构建您想要的颜色,然后在
set\u background\u color
中使用它们。我们可以在
映射
调用之外使用huxtable的
by_colorspace
,如下所示。同样,按列分别完成:

# this is hairy. Details in ?"huxtable::mapping-functions"
colors1 <- by_colorspace("orange", "white", "green")(tbl_B, 1:6, 1, 
      matrix(NA, 6, 1))
colors2 <- by_colorspace("orange", "white", "green")(tbl_B, 1:6, 2, 
      matrix(NA, 6, 1))

tbl_A %>% 
  set_background_color(everywhere, 1:2, cbind(colors1, colors2)) %>% 
  huxtable::add_colnames() 

而不是分别调用每一列的<代码> MAP>…< />代码。< /P>是否提交给HUXTABLE,或者您可以考虑其他表方法吗?这里是flextable的一个解决方案:非常感谢@dash2为您提供了出色且非常有用的解决方案!非常感谢您考虑将

colwise=TRUE
选项包含在huxtable 4.8.0.1中。它现在已经出来了(实际上是在4.7.1中)。
tbl_A %>% 
  map_background_color(everywhere, 1, by_colorspace("orange", "white", "green")) %>%
  map_background_color(everywhere, 2, by_colorspace("orange", "white", "green")) %>%
  huxtable::add_colnames() 
# this is hairy. Details in ?"huxtable::mapping-functions"
colors1 <- by_colorspace("orange", "white", "green")(tbl_B, 1:6, 1, 
      matrix(NA, 6, 1))
colors2 <- by_colorspace("orange", "white", "green")(tbl_B, 1:6, 2, 
      matrix(NA, 6, 1))

tbl_A %>% 
  set_background_color(everywhere, 1:2, cbind(colors1, colors2)) %>% 
  huxtable::add_colnames() 
colors_all <- by_colorspace("orange", "white", "green")(tbl_B, 1:6, 1:2, 
  matrix(NA, 6, 2))

tbl_A %>% 
  set_background_color(everywhere, 1:2, colors_all) %>% 
  huxtable::add_colnames() 
tbl_A %>% 
  map_background_color(everywhere, 1:2, 
    by_colorspace("orange", "white", "green", colwise = TRUE))