gt_plt_dot: Add a color dot and thin bar chart to a table

View source: R/gt_dot_bar.R

gt_plt_dotR Documentation

Add a color dot and thin bar chart to a table

Description

This function takes a data column and a categorical column and adds a colored dot and a colored dot to the categorical column. You can supply a specific palette or a palette from the {paletteer} package.

Usage

gt_plt_dot(
  gt_object,
  column,
  category_column,
  palette = NULL,
  max_value = NULL
)

Arguments

gt_object

An existing gt table object of class gt_tbl

column

The column which supplies values to create the inline bar plot

category_column

The category column, where a colored dot and bar will be added

palette

The colors or color function that values will be mapped to. Can be a character vector (eg c("white", "red") or hex colors) or a named palette from the {paletteer} package.

max_value

A single numeric value indicating the max value, if left as NULL then the range of the column values will be used

Value

a gt_tbl

Examples

library(gt)
dot_bar_tab <- mtcars %>%
  head() %>%
  dplyr::mutate(cars = sapply(strsplit(rownames(.)," "), `[`, 1)) %>%
  dplyr::select(cars, mpg, disp) %>%
  gt() %>%
  gt_plt_dot(disp, cars, palette = "ggthemes::fivethirtyeight") %>%
  cols_width(cars ~ px(125))

Figures

gt_dot_bar.png

See Also

Other Themes: gt_plt_bullet(), gt_plt_conf_int(), gt_theme_538(), gt_theme_dark(), gt_theme_dot_matrix(), gt_theme_espn(), gt_theme_excel(), gt_theme_guardian(), gt_theme_nytimes(), gt_theme_pff()


gtExtras documentation built on Sept. 16, 2023, 1:08 a.m.