我認爲下面的代碼可以用於在文檔的一個部分生成一個圖,但該圖可以在文檔的後面加入(例如在附錄)。Knitr - 在主文檔中生成圖片,將其呈現在附錄中
但是,最後兩個代碼塊將被重新評估,因此myData的最新定義會在兩個圖中執行。有誰知道解決這個的(除了想出一個不同的名稱myData的第二個數據對象(這真的不是一個選項))
\documentclass[a4paper,11pt]{article}
\begin{document}
<<TestData1,echo=FALSE>>=
myData <- as.data.frame(cbind(xvar=1:10, yvar = 1:10))
@
<<TestPlot1,include=FALSE>>=
plot(myData)
@
<<TestData2,echo=FALSE>>=
myData <- as.data.frame(cbind(xvar=1:10, yvar = 10:1))
@
<<TestPlot2,include=FALSE>>=
plot(myData)
@
<<APPTestPlot1,dependson='TestPlot1',ref.label="TestPlot1",fig.cap="figCap1",fig.caps="figCaps",fig.env="figure",fig.pos="htb",fig.width=6,fig.height=6,out.width="0.5\\textwidth",include=TRUE,echo=FALSE>>=
@
<<APPTestPlot2,dependson='TestPlot2',ref.label="TestPlot2",fig.cap="figCap2",fig.caps="figCap2s",fig.env="figure",fig.pos="htb",fig.width=6,fig.height=6,out.width="0.5\\textwidth",include=TRUE,echo=FALSE>>=
@
\end{document}
非常感謝!
雖然這個工作,請參閱http://stackoverflow.com/questions/15406028/suppressing-messages-in-knitr-rmarkdown/15406290#15406290 – mnel
謝謝,是的,這個解決方案可以解決這個問題。但是,能夠使用knitr功能並重新使用ref.label選項可以很好,但如果不可行,那麼我將使用\ includegraphics來插入繪圖。 – user1570707
您可以使用'fig.show ='hide''而不是'pdf(); dev.off()',我認爲這是不好的做法:http://i.imgur.com/jrwbX.jpg –