I use the package knitr
for R to create a LaTeX document combining text with embedded R-graphics and output.
Usually they write something like this:
We plot y vs x in a scatter plot and add the least squares line:
<<scatterplot>>=
plot(x, y)
fit <- lm(y~x)
abline(fit)
@
which works great. (For those unfamiliar with knitr
or Sweave
, this code outputs the code and outputs it in the verbatim environment of LaTeX, and also adds the completed graph as a figure in the LaTeX document.)
But now I would like to write a more detailed step-by-step comment, for example:
First we plot y vs x with a scatterplot:
<<scatterplot>>=
plot(x, y)
@
Then we regress y on x and add the least squares line to the plot:
<<addline>>=
fit <- lm(y~x)
abline(fit)
@
, knitr
. addline
, , scatterplot
, . .
knit()
, , plot()
?
, LaTeX , ?
, , .
, grid knitr? 2013
2016 .
2013 :
, knitr ?