Showtext Graphics

2020

The showtext package1 Qiu and Raggett, 2013. provides external font support for graphics devices.

R Markdown provides support for graphics using showtext, but it has to be enabled via a knitr option. The chunk:

```{r, include = FALSE}
knitr::opts_chunk$set(fig.showtext = TRUE)
```

can be included to enable showtext support in all graphics output after it.

library(tidyverse)
library(emplot)
library(showtext)

font_add_google("Space Mono", "space-mono")

mtcars %>%
    mutate(cyl = as.factor(cyl)) %>%
    ggplot(aes(disp, mpg, colour = cyl)) +
        geom_point() +
        theme(text = element_text(family = "space-mono"),
              axis.text = element_text(family = "space-mono"))