How to use otf font in ggplot2 plot?

I want to use otf font in my ggplot2 plot. I am using Mac OS X 10.9. I found http://goo.gl/dFqJhV

But the experimental part won't work for me.

http://goo.gl/rNmIRR doesn't work because I got a lot of errors compiling the branch. The specified branch seems too old.

The solution with cairo_pdf () ( http://goo.gl/LcYFS6 ) works, but not for me, because I want to embed the graphics in knitr file with pdf and / or html output.

0


source to share


1 answer


You can try the showtext package in combination knitr

with a parameter fig.showtext=TRUE

.

Suppose the OTF font has filename "somefont.otf" and you want to use it in R via the last name "myfont" (can be an arbitrary character string). Below is an example of an Rmd file that can be compiled to PDF or HTML:



---
output: pdf_document
---

```{r setup, include=FALSE}
library(showtext)
font.add("myfont", "somefont.otf")
```

```{r fig.showtext=TRUE, fig.width=7, fig.height=7}
plot(cars, family = "myfont")
```

      

+2


source







All Articles