Hello,
I would like to create a heatmap with the data_color
function of the gt
package.
However, it seems that the color values are actually calculated per column and not across
all cells of all the columns which have been selected.
See e.g. the attached table image:
chicken: size M income 65224.5 is lighter than size L sold 4932. And both chicken L sold (4932) and income (102339.0) have the same color value. I would think that this potentially misleading.
How could I scale the values across all columns?
Many thanks. r
library(tidyverse)
library(gt)
df_2 <-
pizzaplace %>%
dplyr::filter(
type %in% c("chicken", "supreme")) %>%
dplyr::group_by(type, size) %>%
dplyr::summarize(
sold = dplyr::n(),
income = sum(price)
)
#> `summarise()` regrouping output by 'type' (override with `.groups` argument)
names(df_2)[3:4]
#> [1] "sold" "income"
df_2 %>%
gt() %>%
data_color(
columns = names(df_2)[3:4],
colors = scales::col_numeric(
palette = c("white", "#3fc1c9"),
domain = NULL
)
)
Created on 2020-10-14 by the reprex package (v0.3.0)