Is there a way to save code and drawing together in knitrusing the environment figurein LaTeX?
This style:
\documentclass{article}
\begin{document}
writing
<<cars, fig.cap="this is a figure.">>=
with(mtcars, plot(mpg, disp))
@
writing
\end{document}
will cause the shape to be in a float in LaTeX - this is what I want, except that the shape is floating away from the code .
My current workaround is manually recording the shape environment in LaTeX:
\begin{figure}
<<cars2>>=
with(mtcars, plot(mpg, disp))
@
\caption{this is a figure.}
\end{figure}
Is there a more elegant way I can do this in knitr? Adding a parameter is fig.pos='h'not enough. fig.show='asis'also not executed.
Do I need to write my own hook? Can this be done easily ?
source
share