| fmt_symbol_first {gtExtras} | R Documentation |
Aligning first-row text only
Description
This is an experimental function that allows you to apply a suffix/symbol to only the first row of a table, and maintain the alignment with whitespace in the remaining rows.
Usage
fmt_symbol_first(
gt_object,
column = NULL,
symbol = NULL,
suffix = "",
decimals = NULL,
last_row_n = NULL,
symbol_first = FALSE,
scale_by = NULL,
gfont = NULL
)
Arguments
gt_object |
An existing gt table object of class |
column |
columns to apply color to with tidyeval |
symbol |
The HTML code or raw character string of the symbol being inserted, optionally |
suffix |
a suffix to add, optionally |
decimals |
the number of decimal places to round to |
last_row_n |
Defining the last row to apply this to. The function will attempt to guess the proper length, but you can always hardcode a specific length. |
symbol_first |
TRUE/FALSE - symbol before after suffix. |
scale_by |
A numeric value to multiply the values by. Useful for scaling percentages from 0 to 1 to 0 to 100. |
gfont |
A string passed to |
Value
An object of class gt_tbl.
Figures
Function ID
2-1
See Also
Other Utilities:
add_text_img(),
fa_icon_repeat(),
fmt_pad_num(),
fmt_pct_extra(),
generate_df(),
gt_add_divider(),
gt_badge(),
gt_double_table(),
gt_duplicate_column(),
gt_fa_column(),
gt_fa_rank_change(),
gt_fa_rating(),
gt_fa_repeats(),
gt_highlight_cols(),
gt_highlight_rows(),
gt_img_border(),
gt_img_circle(),
gt_img_multi_rows(),
gt_img_rows(),
gt_index(),
gt_merge_stack_color(),
gt_merge_stack(),
gt_two_column_layout(),
gtsave_extra(),
img_header(),
pad_fn(),
tab_style_by_grp()
Examples
library(gt)
fmted_tab <- gtcars %>%
head() %>%
dplyr::select(mfr, year, bdy_style, mpg_h, hp) %>%
dplyr::mutate(mpg_h = rnorm(n = dplyr::n(), mean = 22, sd = 1)) %>%
gt::gt() %>%
gt::opt_table_lines() %>%
fmt_symbol_first(column = mfr, symbol = "$", last_row_n = 6) %>%
fmt_symbol_first(column = year, suffix = "%") %>%
fmt_symbol_first(column = mpg_h, symbol = "%", decimals = 1) %>%
fmt_symbol_first(hp, symbol = "°", suffix = "F", symbol_first = TRUE)