r - knitr: how to reference a plot from a multi-plot chunk -
i have .rnw
document want reference plot multi-plot chunk. how do this?
example:
\documentclass{article} \begin{document} <<single_chunk, fig.cap="hi">>= plot(1:5) @ can reference single chunk fine! see \ref{fig:single_chunk}. <<multichunk, fig.cap="hello">>= plot(1:10) plot(10:1) @ first figure great, \ref{fig:multichunk}. try again \ref{fig:multichunk-1}. \end{document}
both these attempts result in ??
.
just have @ generated *.tex file! here's relevant part (i took freedom align bit more nicely knit
does):
\begin{knitrout} \definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe} \begin{alltt} \hlkwd{plot}\hlstd{(}\hlnum{1}\hlopt{:}\hlnum{10}\hlstd{)} \end{alltt} \end{kframe} \begin{figure} \includegraphics[width=\maxwidth]{figure/multichunk-1} \caption[hello]{hello} \label{fig:multichunk1} \end{figure} \begin{kframe}\begin{alltt} \hlkwd{plot}\hlstd{(}\hlnum{10}\hlopt{:}\hlnum{1}\hlstd{)} \end{alltt} \end{kframe} \begin{figure} \includegraphics[width=\maxwidth]{figure/multichunk-2} \caption[hello]{hello} \label{fig:multichunk2} \end{figure}
so, if closely, you'll note multiplot figures named fig:multichunk1
, fig:multichunk2
. , indeed, if reference these (\ref{fig:multichunk1}
, ...), works fine.