Recompile ggplot2 fonts while importing to LaTeX

214 views Asked by At

Is there a way to get the fonts of a R plot reformated while compiling the global .tex file?

For example something similar to the exporting option of the Inkscape software, allowing to export a .pdf_tex file containing the text along with a .pdf containing the graphics.

Thanks in advance

1

There are 1 answers

0
Konrad Rudolph On BEST ANSWER

Your best bet is to produce a plot output that is itself wholly LaTeX, rather than separating font and graphics. This is possible by using the tikz graphics device:

local({
    on.exit(dev.off())
    tikz('foo.tex')
    ggplot(iris) + aes(Petal.Width, Petal.Length) + geom_point()
})

This will output a TeX file containing graphics primitives that can be used via the TikZ package for LaTeX. The drawback is that compiling complex TikZ graphics to PDF can be quite slow; however, it is possible to cache the graphics so that they do not need to be re-compiled on every LaTeX run of the main document.