I am having issues trying to implement the following solution (from How to add icons to ggplot captions and titles?) in a quarto file.
library(ggplot2)
library(ggtext)
library(showtext)
#> Loading required package: sysfonts
#> Loading required package: showtextdb
library(ggrepel)
library(cowplot)
font_add_google("Martel", family = "title")
font_add_google("Libre Caslon Display", family = "subtitle")
font_add_google("Space Mono", family = "axis")
font_add_google("Spartan", family = "caption")
fa_path <- systemfonts::font_info(family = "Font Awesome 6 Brands Regular")[["path"]]
font_add(family = "fa-brands", regular = fa_path)
showtext_auto()
ggplot(babynames, aes(x = year, y = prop)) +
geom_step(size = 0.5, show.legend = FALSE, direction = "hv") +
theme_bw() +
labs(
x = "Year",
y = "Proportion",
title = "How Unique are Names in the United States?",
subtitle = "This visualization illustrates the proportion of most given baby names in that year between 1880 and 2017",
caption = "Source: {babynames} package | Plot: <span style='font-family: \"fa-brands\"'></span> muhammetozkrca | TidyTuesday-Week 12"
) +
background_grid(major = "none", minor = "none") +
theme(
plot.title = element_text(hjust = 0.5, family = "title", size = 20),
plot.subtitle = element_markdown(hjust = 0.5, family = "subtitle", size = 14),
plot.caption = element_markdown(hjust = 0.5, size = 14),
legend.position = c(0.9, 0.6),
legend.justification = "center",
legend.title = element_text(family = "caption", hjust = 1, vjust = 0.7),
legend.title.align = 0.5,
axis.title.x = element_text(family = "axis"),
axis.title.y = element_text(family = "axis"),
panel.border = element_blank(),
axis.ticks = element_blank()
)
As the answer points out, I need to call the font awesome fonts via
fa_path <- systemfonts::font_info(family = "Font Awesome 6 Brands Regular")[["path"]]
font_add(family = "fa-brands", regular = fa_path)
I can't get this to work. Through other post suggestions I've tried installing the Font Awesome 6 Brands-Regular-400.otf
(from the desktop verstion) as well as fa-brands-400.ttf
(from the web version). I've run them separately as they are named the same.
Trying to trouble shoot I've noticed that
fa_path <- systemfonts::font_info(family = "fa-brands-400")[["path"]]
fa_path <- systemfonts::font_info(family = "Font Awesome 6 Brands Regular")[["path"]]
both return "C:\\WINDOWS\\Fonts\\arial.ttf"
, which leads me to believe the calls aren't even pointing to the correct files.