Latex Font in a ggplot
First one needs to go to the link below and download the TTFs of latin modern roman (standard latex font).
For mac: click on each ttf file and click install.
For windows: copy paste files to C:/windows/fonts
then run font_import(pattern = “lmroman*”) once in R to add fonts.
library(extrafont)
library(tidyverse)
# link www.fontsquirrel.com/fonts/latin-modern-roman
# execute once to add fonts:
# font_import(pattern = "lmroman*")
loadfonts()
data <- data.frame(x=1:10, y=1:10)
p <- data %>% ggplot(aes(x, y)) + geom_point() +
theme(text = element_text(size=10, family="LM Roman 10")) + ggtitle("for the boys")
p + theme(plot.subtitle = element_text(vjust = 1),
plot.caption = element_text(vjust = 1)) +labs(subtitle = "lil subtitle i guess",
caption = "Source: idk, 2018")

data(mtcars)
mtcars %>% ggplot(aes(x=mpg, y=disp)) + geom_col(aes(col=cyl)) +
theme(text = element_text(size=10, family="LM Roman 10")) + ggtitle("for the boys")


www.fontsquirrel.com/fonts/latin-modern-roman


RMarkdown
On windows:
Add global chunk options at beginning:

On mac:
No additional dev specification needed. Can mute this line, if you switch to mac from windows.

Or you add this if() clause:

For further information regarding RMarkdown, ggplot2 and custom fonts go to:
https://www.andrewheiss.com/blog/2017/09/27/working-with-r-cairo-graphics-custom-fonts-and-ggplot/