Using otf-fonts in Knitr’s LaTeX-Documents

As I mentioned earlier I’ve wanted to use otf-fonts in ggplot2-graphics Rmd-Files The next step is to use them in Knitr‘s RMarkdown-documents. That’s simple: Just use it as I showed earlier. 1 2 3 4 5 6 7 8 9 10 11 title: "demo" output: html_document ```{r} library(ggplot2) ggplot(mtcars, aes(x=wt, y=mpg, color=factor(gear))) + geom_point() + ggtitle("Fuel Efficiency of 32 Cars") + xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") + theme(text=element_text(size=16, family="Source Code Pro")) ``` Rnw-Files But using these fonts in Rnw-files — that’s embedded R-code in LaTeX-files — seems to be a little more complex.

Using TeXnicle as editor for knitr-documents

TeXnicle is my favourite editor for writing LaTeX documents. It is available for Max OS X. So I’d like to use it when writing knitr‘s Rnw-files. Rnw-files are LaTeX-files with embedded R-code in it. So Rnw-files need to be preprocessed. The result is a tex-file which will be compiled by pdflatex or xelatex. Processing is done by so called engines. TeXnicle comes with a bunch of different engines. You can see them in preferences (hit ⌘-,) on tab “Typesetting”.

How to use custom otf-fonts in ggplot2 graphics

Sometimes you want to use some custom fonts in your ggplot2 graphics. Years ago there was a good article in [revolutionanalytics.com]. But this article states that if you want to use otf-fonts instead of ttf-fonts you have to use some experimental packages: 1 2 3 library(devtools) install_github('wch/Rttf2pt1') install_github('wch/extrafont') But as time goes by the evolution of R-packages progresses. So now you can use otf-fonts in ggplot2 graphics. I’m using Source Code Pro as custom font because I can identify this font really good because of its “zeros”.

Just launched: rstats-tips.net

I really like to work with R. So I want to share here some of my experience, tips and tricks I use in my daily work. Most of the time I use the following R-packages: ggplot2 dplyr RGoogleAnalytics knitr