我想使用knitr包和chunk选项在beamer中创建一个动画fig.show='animate',其中数字被覆盖而不是替换类似于\ multiinclude默认情况下的工作方式.
一个最小的非工作示例将是以下(Rnw文件),我希望每个点一个接一个地添加到动画中的现有绘图.
\documentclass{beamer}
\usepackage{animate}
\begin{document}
\begin{frame}[fragile]
<<fig.show='animate', fig.width=5, fig.height=5, size='tiny', out.width='.8\\linewidth', fig.align='center', echo=FALSE>>=
x = 1:2
plot(x,x,type="n")
for (i in 1:length(x)) {
points(x[i],x[i])
}
@
\end{frame}
\end{document}
Run Code Online (Sandbox Code Playgroud)
从看knitr显卡手册,它指出地块的两个来源是plot.new()和grid.newpage(),但有一个脚注看到?recordPlot.所以我尝试recordPlot()在points命令之后添加(并且还添加透明背景par(bg=NA),但这不起作用,因为只创建了一个图.
最小的工作示例如下
\documentclass{beamer}
\usepackage{animate}
\begin{document}
\begin{frame}[fragile]
<<fig.show='animate', fig.width=5, fig.height=5, size='tiny', out.width='.8\\linewidth', fig.align='center', echo=FALSE, fig.keep='all'>>=
x = 1:2
plot(x,x,type="n")
for (i in 1:length(x)) {
for (j in 1:i) points(x[j],x[j])
}
@
\end{frame}
\end{document}
Run Code Online (Sandbox Code Playgroud)
但这似乎有些过分,因为每个人都会重新绘制情节以及前面所有的观点.
有没有办法摆脱循环j?或者其他一些在beamer/knitr中叠加图的方法?如果是,我的代码如何修改以实现这一目标?