Skip to contents

Add a 'badge' based on values and palette

Usage

gt_badge(gt_object, column, palette = NULL, alpha = 0.2)

Arguments

gt_object

An existing gt table object

column

The column to convert to badges, accepts tidyeval

palette

Name of palette as a string. Must be either length of 1 or a vector of valid color names/hex values of equal length to the unique levels of the column (ie if there are 4 names, there need to be 4x colors). Note that if you would like to specify a specific color to match a specific icon, you can also use a named vector like: c("angle-double-up" = "#009E73", "angle-double-down" = "#D55E00","sort" = "#000000")

alpha

A numeric indicating the alpha/transparency. Range from 0 to 1

Value

gt table

Examples

library(gt)
head(mtcars) %>%
  dplyr::mutate(cyl = paste(cyl, "Cyl")) %>%
  gt() %>%
  gt_badge(cyl, palette = c("4 Cyl"="red","6 Cyl"="blue","8 Cyl"="green"))

Figures