Skip to contents

This function adds a centered title, subtitle, and a key or legend at the top of a gt table. The key/legend is passed through as a tibble containing colors and labels. Labels can be placed either inside or outside the color boxes.

Usage

gt_centered_legend(
  gt_table,
  key_info,
  heading = "Centered Title",
  subtitle = "Centered Subtitle",
  label_placement = "outside"
)

Arguments

gt_table

A gt table object to modify.

key_info

A tibble containing two columns: color (hex color codes) and label (the corresponding text labels).

heading

Character. The main title text for the table. Defaults to "Centered Title".

subtitle

Character. The subtitle text for the table. Defaults to "Centered Subtitle".

label_placement

Character. Either "inside" or "outside", specifying whether the labels should be inside or outside the color boxes. Defaults to "outside".

Value

Returns a modified gt table with a centered title, subtitle, and a key.

Details

The function creates a centered title, subtitle, and a legend based on the provided key information (colors and labels). If label_placement is "inside", the labels will be placed inside the colored boxes; if "outside", they will be placed next to the colored boxes.