What I need is something like this:
The problem with this R package is that you can't export into pdf format to include in a LaTeX document. Any suggestions?
You can’t export R to PDF directly (afaik), but you can export to TikZ, which is a drawing package for LaTeX. You use an R package called tikzDevice. From the tikzDevice project page:
On TeXample, there’s an example demonstrating the use of tikzDevice to plot a normal distribution and a linear model. That gives you the basic flavour, and then the package documentation goes into it in more detail.
Plotting your R graphs in TikZ means that the graph labels inherit the style of your LaTeX document (for example, if you’re using a different font), and you can embed arbitrary LaTeX in the labels. The TikZ it produces isn’t wonderfully pretty (imo), but it gets the job done, and it can be edited quickly in a pinch.
Normally I output my R code with tikzDevice to a subfolder of my working directory called
Just as an example, here’s a scatterplot made in R with tikzDevice: