13 Tables

13.1 Some packages to build tables in R

13.2 Table parts

  • Ref.: Gohel, D. Using the flextable R package, Chapter 3

13.3 Merging cells

  • merge_at: Merge flextable cells into a single one. All rows and columns must be consecutive.
  • merge_h: Merge flextable cells horizontally
  • merge_v: Merge flextable cells vertically

13.4 Example - merge

tab <- flextable(head(mtcars[,c(1:8)]))
tab <- merge_v(tab, j=c("cyl","vs"))

13.5 Example - merge

tab <- flextable(head(mtcars[,c(1:8)]))
tab <- merge_at(tab, i=1:2, j=1, part="body")

13.6 Define displayed values and mixed content

tab <- flextable(head(mtcars[,c(1:8)]))
tab <- mk_par(tab, j=1, 
    value=as_paragraph("Miles/(US) gallon"), 
        part="header")

13.7 Define displayed values and mixed content

tab <- flextable(head(mtcars[,c(1:8)]))
tab <- mk_par(tab, j=1, 
    value=as_paragraph("Miles/(US) gallon"), 
        part="header")
tab <- width(tab, j=1, width=2) # Column width
tab <- align(tab, part="all", 
            align="center") # Text alignment

13.8 Highlights

tab <- flextable(head(mtcars[,c(1:8)]))
tab <- highlight(tab, j="hp", i = ~ hp > 100, color="green")
tab <- append_chunks(tab, i = ~ mpg < 20, j="cyl",
      as_chunk("***", props=fp_text_default(color="red")))