knitr requires R 2.14.0 or better.
It is now supported in the
RStudio. In your Tools :: Options sclick Sweave and choose "Weave Rnw
files with : knitr
install.packages('knitr', dep=T)
And you must have a version of LaTeX, usually MikTex on Windows or
texLive on Linux. You may also want a frontend for that like TeXMaker
on Windows.
To decrease font size, redefine knitrout environment in the document header.
\ifdefined\knitrout
\renewenvironment{knitrout}{\begin{footnotesize}}{\end{footnotesize}}
\else
\fi
<<setup, echo=F,results=hide>>= opts_chunk$set(fig.width=5, fig.height=4, out.width='.5\\linewidth', dev='pdf', concordance = TRUE) options(width=88, max.print="70", replace.assign=TRUE, digits=3, show.signif.stars=FALSE) @
Code chunk options:
<<bwplot, fig=T, dev=pdf, fig.width=10, fig.height=4, out.width='.95\\linewidth', cache =T>>= data(singer) bwplot(voice.part ~ height, data=singer, xlab="Height (inches)") @
Do not need to put lattice and ggplot commands within a print(...)
call as in Sweave.
Choose from many devices (png or tikz, for
example)
Set fig.height and fig.width to get axis labels to be
right proportional to plot window size. Smaller numbers make labels
bigger.
out.height and out.width relative to
\linewidth or \textwidth
to get settings on the page.
Use cache=TRUE
to avoid repeatedly computing the same values.
Appendix: to rerun the code and show output, refer to the same label created above.
<< ref.label=bwplot, echo=TRUE>>= @
That repeats the code, and reruns it. Use eval=FALSE to omit results.