如何按行(而不是整列)在 flextable 中使用条件格式
How to use conditional formating in flextable by row (not entire columns)
尝试在 flextable 中使用 scales::col_numeric 函数来有条件地仅格式化 table 的一部分。
使用 flextable 自己的文档:
library(flextable)
ft_2 <- flextable(head(iris))
colourer <- col_numeric(
palette = c("wheat", "red"),
domain = c(0, 7))
bg(ft_2,
j = c("Sepal.Length", "Sepal.Width",
"Petal.Length", "Petal.Width"),
bg = colourer)
但是如果只格式化前两行会导致错误。
bg(ft_2,
i = 1:2,
j = c("Sepal.Length", "Sepal.Width",
"Petal.Length", "Petal.Width"),
bg = colourer)
x$data[i, j] <- 值错误:
要替换的项目数不是替换长度的倍数
在着色器中使用 debug() 显示 x 是整列而不是前 2 行。
非常感谢任何帮助。
这可能是 packageVersion('flextable')
的问题,因为它适用于 (0.6.6
) 和 packageVersion('scales')
1.1.1`
library(flextable)
ft_2 <- flextable(head(iris))
colourer <- col_numeric(
palette = c("wheat", "red"),
domain = c(0, 7))
bg(ft_2,
i = 1:2,
j = c("Sepal.Length", "Sepal.Width",
"Petal.Length", "Petal.Width"),
bg = colourer)
-输出
尝试在 flextable 中使用 scales::col_numeric 函数来有条件地仅格式化 table 的一部分。
使用 flextable 自己的文档:
library(flextable)
ft_2 <- flextable(head(iris))
colourer <- col_numeric(
palette = c("wheat", "red"),
domain = c(0, 7))
bg(ft_2,
j = c("Sepal.Length", "Sepal.Width",
"Petal.Length", "Petal.Width"),
bg = colourer)
但是如果只格式化前两行会导致错误。
bg(ft_2,
i = 1:2,
j = c("Sepal.Length", "Sepal.Width",
"Petal.Length", "Petal.Width"),
bg = colourer)
x$data[i, j] <- 值错误: 要替换的项目数不是替换长度的倍数
在着色器中使用 debug() 显示 x 是整列而不是前 2 行。
非常感谢任何帮助。
这可能是 packageVersion('flextable')
的问题,因为它适用于 (0.6.6
) 和 packageVersion('scales')
1.1.1`
library(flextable)
ft_2 <- flextable(head(iris))
colourer <- col_numeric(
palette = c("wheat", "red"),
domain = c(0, 7))
bg(ft_2,
i = 1:2,
j = c("Sepal.Length", "Sepal.Width",
"Petal.Length", "Petal.Width"),
bg = colourer)
-输出