knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(varnish)
table_contents <- airquality[1:10,c(6, 1:4)] table_contents
The varnish()
function is a wrapper for several functions, combining several steps of finishing a table:
style_table()
add_headers()
underline_header()
colwidths()
table_contents %>% flextable::flextable() %>% varnish(headers = list(c("", "Air quality"), c("Day", "Ozone", "Solar", "Wind", "Temp")), colspan = list(c(1, 4), NULL), underline_j = 2, widths = c(10, 23, 23, 23, 23))
The add_headers()
function deletes the existing table header and then adds (multiple) column headers. It is a wrapper for flextable::delete_part()
and flextable::add_header_row()
.
table_contents %>% flextable::flextable() %>% add_headers(headers = list(c(NA, "Air quality"), c("Day", "Ozone", "Solar", "Wind", "Temp")), colspan = list(c(1, 4), NULL))
The style_table()
function is used to apply an overall design to a flextable. It is recommended to use add_headers()
(to add column headers) before applying this function.
table_contents %>% flextable::flextable() %>% add_headers(c("Day", "Ozone", "Solar", "Wind", "Temp")) %>% style_table()
table_contents %>% flextable::flextable() %>% add_headers(headers = list(c(NA, "Air quality"), c("Day", "Ozone", "Solar", "Wind", "Temp")), colspan = list(c(1, 4), NULL)) %>% style_table() %>% underline_header(j = 2)
table_contents %>% flextable::flextable() %>% add_headers(headers = list(c(NA, "Air quality"), c("Day", "Ozone", "Solar", "Wind", "Temp")), colspan = list(c(1, 4), NULL)) %>% style_table() %>% underline_header(j = 2) %>% colwidths(c(10, 23, 23, 23, 23))
table_contents %>% flextable::flextable() %>% add_headers(headers = list(c(NA, "Air quality"), c("Day", "Ozone", "Solar", "Wind", "Temp")), colspan = list(c(1, 4), NULL)) %>% style_table() %>% underline_header(j = 2) %>% add_footnote("Daily air quality measurements in New York, May 1973.")
table_contents %>% flextable::flextable() %>% add_headers(headers = list(c(NA, "Air quality"), c("Day", "Ozone", "Solar", "Wind", "Temp")), colspan = list(c(1, 4), NULL)) %>% style_table() %>% underline_header(j = 2) %>% add_footnote("Daily air quality measurements in New York, May 1973.") %>% add_footnote("\u00B0F", i = 2, j = 5, part = "header", symb = marker(1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.