Closed JackLich10 closed 3 years ago
Love it, please keep the ideas coming!
I would ask, if you could simplify the reprex
, that would be great! See below:
library(dplyr)
library(gt)
library(gtExtras)
my_palette <- c("#ffffff", "#f2fbd2", "#c9ecb4", "#93d3ab", "#35b0ab")
fa_palette <- c("angle-double-up" = "#009E73",
"angle-double-down" = "#D55E00",
"sort" = "#000000")
df_in <- readRDS(url("https://github.com/JackLich10/JackLich10/blob/main/gtextra_data.rds?raw=true"))%>%
select(trend, trend2)
df_in %>%
gt() %>%
gt_fa_column(column = trend, palette = fa_palette) %>%
gt_fa_column(column = trend2, palette = fa_palette)
The latest package version (v0.2.15) has enabled support for named color vectors. Essentially the names will be mapped to the levels and the colors will be mapped to the actual colors.
So your example:
c("angle-double-up" = "#009E73",
"angle-double-down" = "#D55E00",
"sort" = "#000000")
Works now with the internals.
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(gt)
library(gtExtras)
my_palette <- c("#ffffff", "#f2fbd2", "#c9ecb4", "#93d3ab", "#35b0ab")
fa_palette <- c("angle-double-up" = "#009E73",
"angle-double-down" = "#D55E00",
"sort" = "#000000")
df_in <- readRDS(url("https://github.com/JackLich10/JackLich10/blob/main/gtextra_data.rds?raw=true"))%>%
select(trend, trend2)
df_in %>%
slice(1:10) %>%
gt() %>%
gt_fa_column(column = trend, palette = fa_palette) %>%
gt_fa_column(column = trend2, palette = fa_palette) %>%
gtsave("test-tab.png")
Created on 2021-10-04 by the reprex package (v2.0.1)
Awesome, and will do for future reprex's
The only reason I'm creating these issues is because the package is awesome! But, I have another feature request. Basically, in my doubled table from the other issue, I want to use font-awesome icons to show trends. My issue is that because the values of the icons do not line up in the same order across the
trend
andtrend2
columns, the call withingtExtras::gt_fa_column
ofunique(x)
changes based on the column, resulting in different colors being mapped to the same icons across the two columns. I'm hoping that a solution would be to input a named palette vector like I have below to solve this issue. Thanks for all your help and work!Results in:
Note how Rodgers and Burrow have different icons, but are mapped the same color.