我正在尝试使用两个变量对数据进行分组:Country 和 State_Province。我想在 R 中使用 'flextable' 来执行此操作,并且我还希望这两个变量在结果表中彼此相邻,由竖线分隔。
然而,使用 merge_v 似乎摆脱了垂直条,我不知道如何将它重新添加进去。
这是一个可重现的小例子:
library(flextable)
library(dplyr)
big_border = fp_border(color="#2c3a51" , width = 2)
std_border = fp_border(color="#2c3a51" , width = 1)
df <- data.frame(Country = c("US", "US", "US", "Canada", "Canada", "Canada"),
State_Province = c("CA", "CA", "NY", "Quebec", "Quebec", "Alberta"),
data = LETTERS[1:6])
df %>%
flextable() %>%
vline( border = std_border, part = "all" ) %>%
border_outer(part="all", border = big_border ) %>%
merge_v(j = c("Country", "State_Province") )
相反,我一直在添加一个 serperator 并在演示之前将其删除。
myft <- df %>%
flextable(., col_keys = c("Country", "separator", "State_Province", "data"))
myft <- border(myft, j = ~ separator, border = fp_border(width=0), part = "all")
myft <- width(myft, j = ~ separator, width = 0)
myft %>%
merge_v(j = c("Country") ) %>%
vline( border = std_border, part = "all" ) %>%
border_outer(part="all", border = big_border ) %>%
merge_v(j = c("State_Province") )