Closed areckenrode closed 1 year ago
Howdy! I'll look into this, but generally I think that NAs are a mistake for the table in this case. By that I mean typically we would be pre-processing the input table, so we could either shift the NA to a meaningful value (ie change NA to "blank") or deal with it on the fly like below:
library(gt)
library(gtExtras)
library(tidyverse)
test_tbl = tibble(col1 = rep(T, 3), col2 = c(T, T, F), col3 = rep(F, 3), col4 = c(T, T, NA))
ex_pal <- c("square-check" = "green", "square-xmark" = "red", "square" = "lightgrey")
test_tab <- test_tbl %>%
mutate(across(where(is_logical),~ case_when(.x ~ "square-check", !.x ~ "square-xmark", is.na(.x) ~ "square"))) %>%
gt()
test_tab
test_tab %>%
gt_fa_column(column = col1:col4, palette = ex_pal)
Thank you for your response and suggestion.
I do apologize - I'd unsuccessfully tried out this option with an older version of this package & assumed it would continue to fail. However, with the newest update, this option does work!
I'd still be interested to see the 'Subset of palette to be used and NAs ignored', but your suggestion is a great option!
Prework
In search of combination of these two features:
Using the example from https://github.com/jthomasmock/gtExtras/issues/70#issuecomment-1264838427 , if we add a fourth column that contains NA, we can get 2 different results.
col4 = c(T, F, NA)
), then the table displays as expected.col4 = c(T, T, NA)
), then the errorThe length of the unique elements must match the palette length
is returned.Proposal
To share a palette for an element across multiple tables or columns by defining that palette, even if sometimes the individual table/column doesn't have the full list of factor values and has NAs.
The current version of the packages allows for:
I desire a third option:
The gtExtras package is extremely cool and very useful. This has been a wonderful resource. I appreciate any guidance you may have on this topic.