LaTeX and R bundle?

I use R to analyze statistics and plot histograms, scatterplots, etc.

And then I need to export all the graphs in PDF format to manually include them in the LaTeX report.

I wonder if there is a way to simplify this process?

I would be happy to write something like:

\chapter{One} \begin{r} qplot(...) \end{r} 

In order for the code between \begin{r} and \end{r} generate a graph, save it somewhere in PDF format and create TeX as follows:

 \begin{figure}[ht!] \includegraphics[width=1\textwidth,height=1\textheight]{/path/to/plot.pdf} \end{figure} 
+6
source share
3 answers

You want knitr .

There are many examples on the website

in your document you can do something like

 <<boring-plots, fig.width=4, fig.height=4, out.width='.4\\linewidth'>>= ## two plots side by side (option fig.show='hold') par(mar=c(4,4,.1,.1),cex.lab=.95,cex.axis=.9,mgp=c(2,.7,0),tcl=-.3,las=1) boxplot(x) hist(x,main='') @ 

Or even configure it so that your

 \begin{r} \end{r} 
Syntax

will work.

pdf output is a minimal example from which the above example

+6
source

See if you can see the 5-minute video on the knitr : http://yihui.name/knitr/ If you don't care what LaTeX is, start at 2:54.

The source code will look like this:

 \chapter{One} <<plot, out.width='1\textwidth', out.height='1\textheight', fig.pos='!ht', fig.cap='your caption'>>= qplot(...) @ 
+10
source

Rstudio + knitr are great

 http://www.rstudio.com/ide/docs/authoring/overview 
+5
source

All Articles