I am trying to create pdf reports using R Markdown. I changed the mainfont in the YAML header and in my function for the plots to Georgia. The text in the report is fine, and when I run the individual code chunks, I see my plot text, but when I knit the report, the plots print without any text. Here is an example of what I have...
---
title: ''
output:
pdf_document:
latex_engine: xelatex
html_document: default
word_document: default
mainfont: Georgia
urlcolor: blue
classoption: landscape
always_allow_html: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(autodep = TRUE)
knitr::opts_chunk$set(warning = FALSE)
knitr::opts_chunk$set(message = FALSE)
knitr::opts_chunk$set(fig.dim = c(11,7))
options(digits=3)
library(dplyr)
library(ggplot2)
library(tidyr)
library(readr)
library(ggpubr)
library(gridExtra)
library(stringr)
library(tinytex)
library(knitr)
library(kableExtra)
library(cowplot)
library(reshape2)
library(extrafont)
font_import()
loadfonts(device = "win")
run_chunk <- FALSE
```
```{r data, include=FALSE}
### Create df from scratch here
measure <- c('msr1', 'msr2', 'msr3')
rate <- c(50, 70, 95)
df <- data.frame(measure, rate)
```
The Markdown text outside of the code chunks works fine.
```{r lollipop_plot, eval=run_chunk}
lolli <- ggplot(df, aes(x=measure, y=rate)) +
geom_segment(aes(x=measure, xend=measure, y=0, yend=rate), color='grey') +
geom_point(size=4, alpha=0.6) +
ylim(0, 100) +
theme_classic() +
theme(axis.text.x=element_text(size=12)) +
theme(axis.text.y=element_text(size=12)) +
xlab('') +
ylab('Measure Percentile') +
ggtitle('Lollipop Plot') +
theme(axis.title.x=element_text(size=14)) +
theme(text=element_text(family="Georgia")) +
coord_flip() +
geom_hline(yintercept=50) +
theme(legend.position='bottom')
print(lolli)
```
I know there are other similar questions, but I have not seen a solution for this issue.