我正在尝试使用ReporteRs包制作FlexTable。我希望能够灵活地指定是否为每个列和行使用cols.vertical和rows.vertical,对于所有ncol()+ 1列边框和所有nrow() - 1行边界。此外,我希望能够在桌子边框的顶部和底部包含较暗的边框。下面使用mtcars数据集显示了列规范的示例,并使用虹膜数据集的子集显示了较暗边框的示例。
library(ReporteRs)
a <- FlexTable(mtcars, body.cell.props = cellProperties(border.style = "none"))
cols.vertical <- c(2, 4, 5)
rows.horizontal <- c(3, 4, 7)
a[, cols.vertical] <- chprop(cellProperties(border.right.width = 1,
border.left.width=0,
border.top.width=0,
border.bottom.width=0))
a[rows.horizontal, ] <- chprop(cellProperties(border.right.width = 0,
border.left.width=0,
border.top.width=0,
border.bottom.width=1))
a[rows.horizontal, cols.vertical] <- chprop(cellProperties(border.right.width=1,
border.left.width=0,
border.top.width=0,
border.bottom.width=1))
b <- FlexTable(iris[1:10,], body.cell.props = cellProperties(border.style="none"))
b[1, ]<- chprop(cellProperties(border.right.width = 0,
border.left.width=0,
border.top.width=2,
border.bottom.width=0))
b[nrow(iris[1:10, ]), ] <- chprop(cellProperties(border.right.width = 0,
border.left.width=0,
border.top.width=0,
border.bottom.width=2))
答案 0 :(得分:0)
不确定它是否完全回答了您的问题,但至少您会得到一些代码。
library(ReporteRs)
bdr_1 <- borderSolid(width=2, color="gray")
bdr_2 <- chprop(bdr_1, color="orange")
a <- FlexTable(mtcars)
a <- setFlexTableBorders(a,
inner.vertical = borderNone(), inner.horizontal = borderNone(),
outer.vertical = bdr_1,
outer.horizontal = bdr_1,
body = TRUE, header = TRUE)
cols.vertical <- c(2, 4, 5)
rows.horizontal <- c(3, 4, 7)
a <- chprop(a, value = bdr_2, i = rows.horizontal, j = cols.vertical, side = "left")
a <- chprop(a, value = bdr_2, i = rows.horizontal, j = cols.vertical, side = "right")
a <- chprop(a, value = bdr_2, i = rows.horizontal, j = cols.vertical, side = "top")
a <- chprop(a, value = bdr_2, i = rows.horizontal, j = cols.vertical, side = "bottom")
a
答案 1 :(得分:0)
大卫的反应非常有帮助,这是我将使用的代码,最后有一些混乱,允许零在cols.vertical
library(ReporteRs)
bdr_1 <- borderSolid(width=1)
bdr_2 <- borderSolid(width=2)
a <- FlexTable(mtcars)
a <- setFlexTableBorders(a,
inner.vertical = borderNone(),
inner.horizontal = borderNone(),
outer.vertical = borderNone(),
outer.horizontal = bdr_2,
body = TRUE, header = FALSE)
a <- setFlexTableBorders(a,
inner.vertical = bdr_1,
inner.horizontal = bdr_1,
outer.vertical = borderNone(),
outer.horizontal = bdr_1,
body = FALSE, header = TRUE)
cols.vertical <- c(1, 2, 4, 5)
rows.horizontal <- c(1, 3, 4, 7)
a <- chprop(a, value = bdr_1, j = cols.vertical[cols.vertical>0], side = "right")
a <- chprop(a, value = bdr_1, i = rows.horizontal, side = "bottom")
if(0 %in% cols.vertical) {
if(1 %in% cols.vertical) {
a <- chprop(a, value = bdr_1, j = 1, side = "left")
a <- chprop(a, value = bdr_1, j = 1, side = "right")
} else {
a <- chprop(a, value = bdr_1, j = 1, side = "left")
}
}
a