I am using R to analyse statistical data and plot histograms, scatter plots etc.
And then I have to export all plots as PDFs to manually include them in LaTeX report.
I wonder if there is any way for simplification of this process?
I would be happy to write something like:
\chapter{One}
\begin{r}
qplot(...)
\end{r}
So that the code between \begin{r}
and \end{r}
would generate a plot, save it somewhere as PDF and produce TeX
like this:
\begin{figure}[ht!]
\includegraphics[width=1\textwidth,height=1\textheight]{/path/to/plot.pdf}
\end{figure}
See if you can be convinced by the 5-min video on knitr
's homepage: http://yihui.name/knitr/ If you only care about LaTeX, start from 2:54.
Your source code would be like this:
\chapter{One}
<<plot, out.width='1\textwidth', out.height='1\textheight', fig.pos='!ht', fig.cap='your caption'>>=
qplot(...)
@
What you want is knitr
.
The website has lots of examples
within 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 set it up so your
\begin{r}
\end{r}
syntax would work.
The pdf output of the minimal example from which the example above comes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With