# NOT RUN {
# library(paletteer)
# Use `countrypops` to create a gt table;
# Apply a color scale to the `population`
# column with `scales::col_numeric`,
# four supplied colors, and a domain
tab_1 <-
countrypops %>%
dplyr::filter(country_name == "Mongolia") %>%
dplyr::select(-contains("code")) %>%
tail(10) %>%
gt() %>%
data_color(
columns = vars(population),
colors = scales::col_numeric(
palette = c(
"red", "orange", "green", "blue"),
domain = c(0.2E7, 0.4E7))
)
# Use `pizzaplace` to create a gt table;
# Apply colors from the `red_material`
# palette (in the `ggsci` pkg but
# more easily gotten from the `paletteer`
# package, info at `info_paletteer()`) to
# to `sold` and `income` columns; setting
# the `domain` of `scales::col_numeric()`
# to `NULL` will use the bounds of the
# available data as the domain
tab_2 <-
pizzaplace %>%
dplyr::filter(
type %in% c("chicken", "supreme")) %>%
dplyr::group_by(type, size) %>%
dplyr::summarize(
sold = dplyr::n(),
income = sum(price)
) %>%
gt(rowname_col = "size") %>%
data_color(
columns = vars(sold, income),
colors = scales::col_numeric(
palette = paletteer::paletteer_d(
palette = "ggsci::red_material"
) %>% as.character(),
domain = NULL
)
)
# }
Run the code above in your browser using DataLab