KirkD-CO
KirkD-CO

Reputation: 1793

Greek letters RMarkdown PDF plots

I'm trying to generate Greek letters in the axis labels or titles of plots in an RMarkdown file that is generating a PDF. When I run the code the editor or in the console, I see the letter fine, but when the PDF is generated, they disappear. In the short example below, I can see that the subscript operation is working but the Greek letter theta isn't present.

I've tried changing the Typeset LaTeX in PDF using: option - I have pdfLaTeX and XeLaTex - but I see no difference.

---
title: "Untitled"
output: pdf_document 
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
plot(1:100, 1:100, xlab = expression(theta[5]))
plot(1:100, 1:100, xlab = expression('theta'[5]))
```

Greek letter missing

Subscript working

Upvotes: 1

Views: 572

Answers (1)

mazbata
mazbata

Reputation: 68

I was using Latin modern font and came across the same problem. The following code fixed it for me. Make sure the math library for the font you are using is called for.

---
title: "Untitled"
output: pdf_document 
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r, fig.showtext=TRUE}
library("showtext")
font_add("LM Roman 10", regular = "/usr/share/texmf/fonts/opentype/public/lm/lmroman10-regular.otf")
font_add("LM Roman 10", regular = "/usr/share/texmf/fonts/opentype/public/lm-math/latinmodern-math.otf")
plot(1:100, 1:100, xlab = expression(theta[5])) 
```

Upvotes: 2

Related Questions