Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed local font in caption text #1819

Open
2 tasks done
datawolf04 opened this issue Aug 6, 2024 · 0 comments
Open
2 tasks done

Embed local font in caption text #1819

datawolf04 opened this issue Aug 6, 2024 · 0 comments
Assignees

Comments

@datawolf04
Copy link

Prework

Proposal

I'd like to be able to tag my table with my social media usernames when I do things like #TidyTuesday, or other community participation activities. We are able to do that with figures, and I'm hoping that this functionality can be brought to gt. I will show you what I mean with this MWE:

# Begin setup code
library(tidyverse)
library(gt)
library(sysfonts)
library(ggtext)
library(showtext)

# This is where I have my fontawesome fonts saved
font_add("fa6-brands", 
         "/usr/share/fonts/fontawesome-free-6.6.0-desktop/otfs/Font Awesome 6 Brands-Regular-400.otf")
gh <- str_glue("<span style='font-family: \"fa6-brands\"'>&#xf09b;</span>")
li <- str_glue("<span style='font-family:\"fa6-brands\"'>&#xf08c;</span>")
caption_text <- str_glue("{gh} github_user {li} linkedin_user")

showtext_auto(enable = TRUE)

I'll use the islands data in the gt package:

islands_tbl <- 
  tibble(
    name = names(islands),
    size = islands
  ) |> 
  arrange(desc(size)) |>
  slice(1:10)

And now I will make the world's dumbest plot:

ggplot(islands_tbl, aes(y=name,x=size)) +
  geom_col() + 
  theme(
    axis.title.y = element_blank(),
    axis.text.x = element_text(angle=-45),
    plot.caption = element_markdown(
      family      = "sans",
      color       = "grey40",
    )
  ) +
  labs(
    title="Dumb plot",
    caption = caption_text
  ) 

dumbPlot

I can make the table in the documentation, adding in a caption:

# Create a display table showing ten of
# the largest islands in the world
gt_tbl <- gt(islands_tbl)

gt_tbl |>
  tab_header(
    title = "Large Landmasses of the World",
    subtitle = "The top ten largest are presented"
  ) |>
  tab_caption("My caption text") 

table1

But I can't use the same caption object from my plot

gt_tbl |>
  tab_header(
    title = "Large Landmasses of the World",
    subtitle = "The top ten largest are presented"
  ) |>
  tab_caption(md(caption_text)) 

table2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants