Closed IvoVillanueva closed 2 years ago
Howdy! I'm refactoring that function, but for now, I'd suggest using the eventual replacement function gtExtras::duplicate_column()
. The keep_column
syntax is not likely to work longterm but we'll see.
See below, and note that disp
and mpg
still exist as columns in the data.
library(gt)
library(gtExtras)
set.seed(37)
df_in <- tibble::rownames_to_column(mtcars) %>%
dplyr::select(rowname, cyl:drat, mpg) %>%
dplyr::group_by(cyl) %>%
dplyr::mutate(target_col = mean(mpg),
target_disp = mean(disp)) %>%
dplyr::slice_sample(n = 3) %>%
dplyr::ungroup()
df_in %>%
gt::gt() %>%
# duplicate the columns for plotting
gt_duplicate_column(mpg, dupe_name = "mpg_plot") %>%
gt_duplicate_column(disp, dupe_name = "disp_plot") %>%
gt_plt_bullet(column = mpg_plot, target = target_col, width = 45,
colors = c("lightblue", "black")) %>%
gt_plt_bullet(column = disp_plot, target = target_disp, width = 45,
colors = c("lightblue", "black")) %>%
gtsave("test.png")
Created on 2021-10-21 by the reprex package (v2.0.1)
Thank you very much Thomas
I've refactored that function internally so that the latest version of gtExtras
works as intended with 2x keep_column
without needing gt_duplicate_column()
although I still like that as an option!
In this example, I would make 3 gt_plt_bullet, and only can make one, how Could I make
mtcars %>% mutate( mean_disp = mean(disp), mean_hp = mean(hp), mean_drat = mean(drat), ) %>% select(disp, mean_disp, hp, mean_hp, drat, mean_drat) %>% gt() %>% gt_plt_bullet(., keep_column = TRUE, column = disp, target = mean_disp, width = 30, colors = c("#f28422","#0e1631") )
when i put 2 bullets
mtcars %>% mutate( mean_disp = mean(disp), mean_hp = mean(hp), mean_drat = mean(drat), ) %>% select(disp, mean_disp, hp, mean_hp, drat, mean_drat) %>% gt() %>% gt_plt_bullet(., keep_column = TRUE, column = disp, target = mean_disp, width = 30, colors = c("#f28422","#0e1631") ) %>% gt_plt_bullet(., keep_column = TRUE, column = hp, target = mean_hp, width = 30, colors = c("#f28422","#0e1631") )