dt_fmt_col: Colour DT column by range

View source: R/dt_format_col.R

dt_fmt_colR Documentation

Colour DT column by range

Description

Colours DT columns based on the minimum and maximum of each column. Defaults to a purple-green colour scheme HULK which is colourblind-friendly, and naturally associates "green" to "good" and "purple" to "bad".

Usage

dt_fmt_col(
  dt,
  columns,
  column_range = NULL,
  colours = c("#9162C5", "#F1F1F1", "#6BA359"),
  reverse_colours = FALSE,
  colour_steps = 100
)

Arguments

dt

a DT object created by DT::datatable()

columns

a character or numeric vector of column identifiers (column names or indices)

column_range

numeric or "auto": either the minimum and maximum range to be coloured, or "auto" which defaults to the max and min of the table column.

colours

A set of hex colours to be passed on to colorRampPalette(), defaults to purple-green

reverse_colours

logical: reverses direction of colour scale

colour_steps

number: how many distinct colours to create, default 100

Value

A DT object with added colour formatting

Examples

DT::datatable(mtcars) |>
  # standard: formats high values as green, low values as purple
  dt_fmt_col(columns = c("hp", "cyl")) |>
  # reverse: formats low values as green, high values as purple
  dt_fmt_col(columns = "mpg", reverse_colours = TRUE) |>
  # custom colours
  dt_fmt_col(columns = "wt", colours = c("orange", "white", "blue"))


tanho63/tantastic documentation built on May 31, 2024, 9 p.m.