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!