R / Sweave:前缀和图形文件命名

时间:2011-12-02 07:53:23

标签: r latex sweave

我是R的新手,而且是Sweave的新手,我正在尝试使用图形。以下是示例代码:

\documentclass[a4paper]{article}
\usepackage{Sweave}  %%%%%%
\SweaveOpts{eps=true}
\begin{document}

<<echo=FALSE>>=
test.frame<-data.frame(year=8:11, value= c(12050,15292,23907,33991))
@

\SweaveOpts{prefix.string=Evolution}
<<label=amount,echo=FALSE,results=hide>>=
postscript('doudou.eps',
            width=6, height=7,
            colormodel="cmyk",
            family = "ComputerModern")
with(test.frame,plot(year, value))
dev.off()
@

\begin{figure}[htbp]
\begin{center}
\includegraphics[width=1\textwidth,angle=90]{doudou.eps}
\end{center}
\end{figure}

\end{document}

What I want to do above?

要对我正在插入的EPS文件进行手动控制,以便我可以在\includegraphics文件本身中拥有Sweave命令。

我正在尝试为该图提供正确的文件名:使用前缀Evolution和标签amount,以便生成的EPS数字将命名为Evolution-amount.eps

What is going wrong?

如您所见,我在R postscript选项中插入文件名,即doudou.eps。如果我不这样做,则Rplots.ps创建名为R的文件。

所以我的代码很好地忽略了我想给我的图形文件的前缀和标签。

我稍后明确要求\includegraphics提出doudou.eps

How I want it to be?

为了能够在图文件名中使用上面提到的前缀和标签,我仍然可以手动控制\includegraphics文件中的Sweave命令。这可能吗?

What is the use of this?

说我正在写论文,我有不同部分的数据。所以有这样的东西会很好:

\SweaveOpts{prefix.string=Paper2}

<<label=section2,echo=FALSE,results=hide>>=

例如我在postscript选项中指定:model.eps

然后该图将被命名为Paper2-section2.model.eps。那可行吗?

我需要手动设置这个名字吗?在随后的\includegraphics命令中。

非常感谢...


更新:2011年12月9日。

在cbeleites的帮助下,一个紧密的解决方案是:

\documentclass[fleqn, a4paper,12pt]{article}
\usepackage[latin1]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{Sweave} %%%%%%
\SweaveOpts{eps=TRUE}



\begin{document}

<<echo=FALSE>>=
test.frame<-data.frame(year=8:11, value= c(12050,15292,23907,33991))
@

\SweaveOpts{prefix.string=Paper2}

<<label=section2, echo=FALSE,results=hide>>=
ps.options ( width=6, height=7, colormodel="cmyk", family = "ComputerModern")
@


<<label=section2, fig=TRUE, include = TRUE, echo=FALSE>>=
with(test.frame,plot(year, value))
@

\end{document} 

在编译时,我得到名为Paper2-section2的EPS和PDF文件。这就像我想的那样接近。

1 个答案:

答案 0 :(得分:3)

你需要使用一个数字块。

    <<fig=TRUE, include = FALSE>>=
    with(test.frame,plot(year, value))
    @
  • 您可以将更多选项传递给图块,例如宽度和高度。

  • 有关更多高级选项,请使用R的postscript选项:

    <<>>=
    ps.options (colormodel="cmyk", family = "ComputerModern")
    @
    
  • 如果这些选项仅适用于一个数字,那么在没有数字块和手动\includegraphics的情况下,您可能会更容易。您可以将文件名提供给ps文件,就好像它是由Sweave图块产生的。

  • 如果\includegraphics的唯一原因是您要控制其选项,请查看graphicx'Gin

    \begin{figure}[htbp]
    \begin{center}
    \setkeys{Gin}{width=\linewidth}
    <<fig=TRUE>>=
    with(test.frame,plot(year, value))
    @
    \end{center}
    \end{figure}
    

我认为Gin也可以使用旋转,但事实并非如此。请参阅https://tex.stackexchange.com/a/31013以获取解释和可能的解决方案。但是,如果旋转只是因为数字出现在侧面(而不是你希望它们是横向),这可以通过R中的正确ps设置来解决(RSiteSearch ()? postscript应该有帮助)。 / p>

相关问题