tags:

views:

2646

answers:

4

I would like to add LaTeX typesetting to elements of plots in R (e.g., the title, axis labels, annotations, etc.) using either the combination of base/lattice or with ggplot2.

Is there a way to get LaTeX into plots using these packages, and if so, how is it done? If not, are there additional packages needed to accomplish this.

For example, in Python matplotlib compiles LaTeX via the text.usetex packages as discussed here: http://www.scipy.org/Cookbook/Matplotlib/UsingTex

Is there a similar process by which such plots can be generated in R?

+1  A: 

Here's one solution, from Frank Harrell:

http://biostat.mc.vanderbilt.edu/wiki/Main/PsFrag

Christopher DuBois
+4  A: 

You can generate tikz code from R: http://r-forge.r-project.org/projects/tikzdevice/

Mica
This package is now on CRAN. http://cran.r-project.org/web/packages/tikzDevice/
Rob Hyndman
+1  A: 

As stolen from here, the following command correctly uses LaTeX to draw the title:

plot(1, main=expression(beta[1]))

See ?plotmath for more details.

Christopher DuBois
Interesting, also good stuff with demo(plotmath)So mathematical notation has to be re-interpreted through plotmath's syntax? That seems like a glorious waste of time, especially if you have an involved LaTeX expression.That's why I like matplotlib's ability to compile LaTeX itself. Is there something that can take LaTeX and generate plotmath syntax?
DrewConway
Not that I know of. There's an interesting post at RWiki about getting latex to work with ggplot2: http://wiki.r-project.org/rwiki/doku.php?id=tips:graphics-ggplot2:mathematicalannotations
Christopher DuBois
+5  A: 
Christopher DuBois