I regularly use rmarkdown (and now distill) to do data investigations to show to clients.
I have in previous jobs 'branded' my output in various ways, particularly using fonts stored locally to my machine to generate PDFs. I am in a new company, where the corporate 'font' is in fact a google font. I am also not restricted (and happily empowered) to generate HTML output instead of PDF, however this has disrupted my workflow slightly.
I had previously used showtext to apply my fonts to ggplot2 in PDF outputs, however I am starting to expect this is not supported for all HTML outputs.
I can successfully generate an html_notebook
output type, I believe because the plot assets are generated in the same session as I'm working in in the IDE, and the notebook output is updated form that environment on a save operation.
However, I am not successfully generating HTML documents that are html_document
, or distill::distill_article
. I believe this is because these documents get generated in a separate (child?) session of R, which seems not to behave with showtext
?
Has anyone successfully generated ggplots with showtext in either of these cases? Has anyone found an alternative approach to formatting ggplots in these cases? Has anyone got an alternative approach (even not ggplot! ) to formatting chart fonts in these cases?
---
title: "Showtext example"
output: html_document
---
Change html_document to html_notebook and distill::distill_article
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(showtext)
library(ggplot2)
font_add_google(name = "Quicksand", family = "Quicksand", regular.wt = 400, bold.wt = 700)
showtext.auto()
theme_set(theme_minimal() + theme(text = element_text(family = "Quicksand")))
df <- data.frame(
gp = factor(rep(letters[1:3], each = 10)),
y = rnorm(30)
)
ggplot(data = df, aes(x = gp, y = y)) +
geom_point()
My error in non-html_notebook
files includes no font could be found for family "Quicksand"