View source: R/gt_color_rows.R
gt_color_rows | R Documentation |
The gt_color_rows
function takes an existing gt_tbl
object and
applies pre-existing palettes from the {paletteer}
package or custom
palettes defined by the user. This function is a custom wrapper around
gt::data_color()
, and uses some of the boilerplate code. Basic use
is simpler than data_color()
.
gt_color_rows(
gt_object,
columns,
palette = "ggsci::red_material",
direction = 1,
domain = NULL,
pal_type = c("discrete", "continuous"),
...
)
gt_object |
An existing gt table object of class |
columns |
The columns wherein changes to cell data colors should occur. |
palette |
The colours or colour function that values will be mapped to |
direction |
Either |
domain |
The possible values that can be mapped. For If |
pal_type |
A string indicating the palette type (one of |
... |
Additional arguments passed to |
An object of class gt_tbl
.
library(gt) # basic use basic_use <- mtcars %>% head(15) %>% gt() %>% gt_color_rows(mpg:disp) # change palette to one that paletteer recognizes change_pal <- mtcars %>% head(15) %>% gt() %>% gt_color_rows(mpg:disp, palette = "ggsci::blue_material") # change palette to raw values vector_pal <- mtcars %>% head(15) %>% gt() %>% gt_color_rows( mpg:disp, palette = c("white", "green")) # could also use palette = c("#ffffff", "##00FF00") # use discrete instead of continuous palette discrete_pal <- mtcars %>% head(15) %>% gt() %>% gt_color_rows( cyl, pal_type = "discrete", palette = "ggthemes::colorblind", domain = range(mtcars$cyl) ) # use discrete and manually define range range_pal <- mtcars %>% dplyr::select(gear, mpg:hp) %>% head(15) %>% gt() %>% gt_color_rows( gear, pal_type = "discrete", direction = -1, palette = "colorblindr::OkabeIto_black", domain = c(3,4,5))
4-2
Other Colors:
gt_color_box()
,
gt_hulk_col_numeric()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.