gt_print: gt wrapper

View source: R/gt_print.R

gt_printR Documentation

gt wrapper

Description

A wrapper function for gt::gt() with some of my preferred formatting for simple tables.

Usage

gt_print(
  x,
  font_name = "Arial",
  font_size = NULL,
  title = NULL,
  subtitle = NULL,
  footer = NULL,
  row_stripes = FALSE,
  row_lines = FALSE,
  align = NULL,
  align_j = NULL,
  col_nms = NULL,
  col_lbls = NULL,
  width = NULL,
  width_j = NULL,
  title_size = NULL,
  subtitle_size = NULL,
  footer_size = NULL,
  span_lbls = NULL
)

Arguments

x

A data.frame object or a tibble (tbl_df).

font_name

single character value, the font family name. With Word and PowerPoint output, the value specifies the font to be used to format characters in the Unicode range (U+0000-U+007F). For "all" table parts.

font_size

For table body. Can be specified as a single-length character vector with units of pixels (e.g., 12px) or as a percentage (e.g., 80\ that the value is given in units of pixels. The px() and pct() helper functions can also be used to pass in numeric values and obtain values as pixel or percentage units.

title

The text for the title.

subtitle

The text for the subtitle which will be displayed below the title.

footer

The text for the footer which will be displayed below the body of the table.

row_stripes

Logical indicating whether to include row stripes.

row_lines

Logical indicating whether to include row lines.

align

Column alignment: a character vector consisting of 'l' (left), 'c' (center), 'r' (right), and/or 'j' (justify). By default or if align = NULL, numeric columns are right-aligned, and other columns are left-aligned. If length(align) == 1L, the string will be expanded to a vector of individual letters, e.g. 'clc' becomes c('c', 'l', 'c').

align_j

Column selection for align argument. Default is 1:length(align).

col_nms

Names of columns to be labelled.

col_lbls

Labels to apply to columns different from column names.

width

A numeric vector with desired column width in absolute pixel values.

width_j

A numeric vector with column indicesto select for width.

title_size

Font size for the title. Can be specified as a single-length character vector with units of pixels (e.g., 12px) or as a percentage (e.g., 80\ is assumed that the value is given in units of pixels. The px() and pct() helper functions can also be used to pass in numeric values and obtain values as pixel or percentage units.

subtitle_size

Font size for the subtitle. Can be specified as a single-length character vector with units of pixels (e.g., 12px) or as a percentage (e.g., 80\ is assumed that the value is given in units of pixels. The px() and pct() helper functions can also be used to pass in numeric values and obtain values as pixel or percentage units.

footer_size

Font size for the footer. Can be specified as a single-length character vector with units of pixels (e.g., 12px) or as a percentage (e.g., 80\ is assumed that the value is given in units of pixels. The px() and pct() helper functions can also be used to pass in numeric values and obtain values as pixel or percentage units.

span_lbls

a named list where the name is the label that gets passed to gt::tab_spanner() and the slot is a character vector of column names.

Value

A customized gt object.

Examples

gt_print(x = head(iris))

gt_print(x = head(iris),
         font_name = "Lato",
         title = "Edgar Anderson's Iris Data",
         title_size = 16,
         subtitle = "Just the head")

gt_print(x = head(iris),
         font_name = "Lato",
         title = "Edgar Anderson's Iris Data",
         title_size = 16)

gt_print(x = head(iris),
         font_name = "Times New Roman",
         title = "Edgar Anderson's Iris Data",
         title_size = 16,
         footer = "The data were collected by Anderson, Edgar (1935). The irises of the Gaspe Peninsula, Bulletin of the American Iris Society, 59, 2–5.")

gt_print(x = head(iris),
         align = c("c"),
         col_lbls = c("Sepal Length",
                      "Sepal Width",
                      "Petal Length",
                      "Petal Width",
                      "Species"))


gt_print(x = head(iris),
         align = c("c"),
         col_nms = names(head(iris)),
         col_lbls = c("Sepal   Length",
                      "Sepal\nWidth",
                      "Petal Length",
                      "Petal Width",
                      "Species"),
         font_size = 16)


gt_print(x = head(iris),
         align = c("c"),
         col_lbls = c("Sepal   Length",
                      "Sepal<br />Width",
                      "Petal Length",
                      "Petal Width",
                      "Species"))


gt_print(x = head(iris),
         align = c("c"),
         col_lbls = c("Length",
                      "Width",
                      "Length",
                      "Width",
                      "Species"),
         span_lbls = list("Sepal" = c("Sepal.Length",
                                      "Sepal.Width"),
                          "Petal" = c("Petal.Length",
                                      "Petal.Width")))

emilelatour/lamisc documentation built on May 20, 2024, 2:42 a.m.