jthomasmock / gtExtras

A Collection of Helper Functions for the gt Package.
https://jthomasmock.github.io/gtExtras/
Other
193 stars 26 forks source link

Feature Request: Support for Custom Font Family in `gt_plt_bar()` Function #135

Open pradisteph opened 2 weeks ago

pradisteph commented 2 weeks ago

Prework Searched for duplicates among the existing issues (both open and closed).

Proposal:

I would like to request the ability to specify a custom font family within the gt_plt_bar() function in the gtExtras package. Currently, the function allows for customisation of font_size and font_style, but it does not provide an option to set the font_family.

Use Case: In my work, I frequently create tables using the gt package combined with the gtExtras::gt_plt_bar() function to display bar charts within table cells. However, I need to ensure consistency in font usage across my tables to adhere to organizational branding guidelines, which specify a particular font family. While I can change the font family for text in gt tables using tab_style(), I cannot apply this customization to the bar charts created by gt_plt_bar().

Minimal Example:

Here is an example of the current usage where I attempt to change the font family, but it doesn't take effect:

library(gt)
library(gtExtras)

# Sample data
data <- data.frame(
  Category = c("A", "B", "C"),
  Value = c(20, 50, 80)
)

# Desired font family (e.g., "Arial Narrow")
narrow_font_family <- "Arial Narrow"

# Create a gt table and add bars
gt_table <- data %>%
  gt() %>%
  gt_plt_bar(column = Value, fill = "lightblue", font_size = 12) %>%
  tab_style(
    style = cell_text(font = narrow_font_family),
    locations = cells_body(columns = "Value")
  )

# The font family does not change for the text within the bars

Desired Outcome: The ability to set the font_family directly within the gt_plt_bar() function or have the function respect the global font family set for the gt table.

For example:

gt_plt_bar(
  column = Value,
  color = "lightblue",
  font_family = "Arial Narrow",  # New feature
  font_size = 12
)

This would allow for greater customization and consistency in tables created with the gtExtras package.

Conclusion: Adding support for a custom font_family in gt_plt_bar() would greatly enhance the flexibility of the function, enabling users to create tables that are fully aligned with their desired styling and branding guidelines.

Thank you for considering this feature request! Stephanie