Issues with fonts in gganimate

Hello! I'm creating a bar chart for a gganimate and running into the same issue (see the chart here). The issue is that the fonts I want loaded don't seem to be working. I continually get the following error:

As you can see in the chart, it switches between different fonts for some reason. Below is the current animation current code that I use:

library(tidyverse)
library(dplyr)
library(ggplot2)
library(gganimate)
library(ggstance)
library(zoo)
library(gifski)
library(shadowtext)
library(showtext)

font_add_google("Encode Sans Condensed", "encode", regular.wt = 400, bold.wt = 600)
font_add_google("Inconsolata", "incon")
showtext_auto()

rb_stats_final <- read_csv(url("https://raw.githubusercontent.com/samhoppen/Fantasy-Evaluator/main/Data/Animation%20Test%20Data.csv"))
all_weeks <- read_csv(url("https://raw.githubusercontent.com/samhoppen/Fantasy-Evaluator/main/Data/Animation%20Weeks%20Data.csv"))


rb_ani <- ggplot(data = rb_stats_final, aes(group = player_name)) +
  geom_barh(aes(x = tot_fpts, y = rank, color = player_name, fill = player_name), stat = 'identity', 
            position = 'identity', show.legend = F, size = 2, width = 0.8) + 
  geom_shadowtext(aes(x = name_loc, y = rank, label = player_name, color = player_name), 
                  hjust = 1, bg.color = 'white', family = "incon", size = 5.5, na.rm = T, bg.r = 0.075, show.legend = FALSE) +
  labs(title = "Highest-scoring Fantasy Running Backs of the Past Decade",
       subtitle = paste0("{all_weeks$week_name[as.numeric(previous_state)]}"),
       caption = "Figure: @SamHoppen | Data: @nflfastR",
       y = "",
       x = "Total Fantasy Points")+
  theme(legend.position = "none",
        plot.title = element_text(size = 24, face = "bold", margin = margin(0,0,10,0), family = "encode"),
        plot.subtitle = element_text(size = 12, margin = margin(0,0,10,0), family = "encode"),
        plot.caption = element_text(size = 12, family = "encode")) +
  transition_states(states = week_order, transition_length = 2, state_length = 1, wrap = F) +
  view_follow(fixed_y = TRUE) +
  enter_fly(y_loc = -21) +
  exit_fly(y_loc = -21) +
  ease_aes('linear')

anim <- animate(rb_ani, nframes = 340, fps = 5,renderer = gifski_renderer(), height = 900, width = 1600)
anim_save(filename = "Animation.gif", animation = anim)

Hopefully this is a good enough reprex. I've been struggling with these issues for about a week now and am getting highly frustrated!

For future reference, it's helpful to pare down your reprex to something more minimal (you can probably reproduce the problem without rendering the 340-frame GIF :wink:, but I waited my minute or so and did it anyhow—too big to upload here, though; maybe the imgur link will work, if not the direct link to the GIF is here).

Anyhow, I get the similar warnings about encode, so it's not specific to Windows or your system library.

Warning messages:
1: In grid.Call(C_stringMetric, as.graphicsAnnot(x$label)) :
  no font could be found for family "encode"
2: In grid.Call(C_stringMetric, as.graphicsAnnot(x$label)) :
  no font could be found for family "encode"
3: In grid.Call(C_stringMetric, as.graphicsAnnot(x$label)) :
  no font could be found for family "encode"

It seems to me the issue must be in showtext, since that's where things are failing.
https://cran.rstudio.com/web/packages/showtext/vignettes/introduction.html

If you can make a more minimal reprex, it'll be easier to isolate where the error is coming from (e.g. Does this happen if you plot a single frame? Does it happen in all of the theme elements, or just one?)

aside: If you're willing to install the google fonts locally, you might be able to accomplish this using the systemfonts package:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.