I would like to use the free font Lato in ggplot2
graphs since the remainder of my R markdown document is set in this font.
The font is installed on my
I tried to make it work using extrafont
but did not succeed. I am still not quite sure but I think it is a bug. Here is a solution using the package showtext
:
---
title: "Embedding Fonts in PDF"
output: pdf_document
urlcolor: blue
---
```{r include=FALSE}
# notice the chunk option 'fig.showtext' that tells R to use the showtext
# functionalities for each ne graphics device opened
knitr::opts_chunk$set(dev = 'pdf', cache = FALSE, fig.showtext = TRUE)
library(ggplot2)
library(showtext)
font_add(family = "Lato", regular = "/Users/martin/Library/Fonts/Lato-Light.ttf")
```
### Plot with newly set standard font (= Lato) {#lato}
```{r echo=FALSE, out.width = '100%'}
ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point() +
ggtitle("Fuel Efficiency of 32 Cars") +
xlab("Weight (x1000 lb)") +
ylab("Miles per Gallon") +
theme(text = element_text(family="Lato"))
```