If the data in gt_plt_bar_stack has a different number of digits, the plot stretches the digits, likely due to the format() function. Passing trim = TRUE into the extra arguments produces the result I would expect as the default behavior.
library(gt)
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
ex_df <- dplyr::tibble(
x = c("Example 1","Example 1",
"Example 1","Example 2","Example 2","Example 2",
"Example 3","Example 3","Example 3","Example 4","Example 4",
"Example 4"),
measure = c("Measure 1","Measure 2",
"Measure 3","Measure 1","Measure 2","Measure 3",
"Measure 1","Measure 2","Measure 3","Measure 1","Measure 2",
"Measure 3"),
data = c(30, 2, 50, 30, 3, 40, 30, 4, 30, 30, 5, 20)
)
tab_df <- ex_df %>%
group_by(x) %>%
summarise(list_data = list(data))
tab_df
#> # A tibble: 4 × 2
#> x list_data
#> <chr> <list>
#> 1 Example 1 <dbl [3]>
#> 2 Example 2 <dbl [3]>
#> 3 Example 3 <dbl [3]>
#> 4 Example 4 <dbl [3]>
ex_tab <- tab_df %>%
mutate(trim_col = list_data) %>%
gt() %>%
gtExtras::gt_plt_bar_stack(column = list_data) %>%
gtExtras::gt_plt_bar_stack(column = trim_col,trim = TRUE,labels = c("trim","=","TRUE"))
If the data in gt_plt_bar_stack has a different number of digits, the plot stretches the digits, likely due to the
format()
function. Passing trim = TRUE into the extra arguments produces the result I would expect as the default behavior.Created on 2021-10-25 by the reprex package (v2.0.1)