在Sweave中将选项[keepaspectratio = true,scale = 0.75]添加到\ includegraphics {}

Mar*_*nts 5 r sweave

我有以下R代码

<<Q1b1, fig=TRUE>>=  
qqnorm(resid(model1), main=NULL)
@
Run Code Online (Sandbox Code Playgroud)

和我想的选项[keepaspectratio =真,标度= 0.75]添加到\ includegraphics {}呼叫,使得上述R代码块生成

\begin{figure}[ht]
\caption{}
\begin{center}
\includegraphics[keepaspectratio=true, scale = 0.75]{filename.pdf}
\label{fig:1}
\end{center}
\end{figure}
Run Code Online (Sandbox Code Playgroud)

我知道你可以使用\ {SweaveOpt宽度= X,HEIGHT = Y}指定的宽度和高度,但我想说明的规模和有它保持身材的宽高比时系统产生的.

是否有捷径可寻?

谢谢

jub*_*uba 9

您可以使用\setkeys{Gin}指令为Sweave文档中的每个图形设置宽度.例如,文档前言中的以下内容使每个图形宽度为页面上文本宽度的80%:

\setkeys{Gin}{width=0.8\textwidth}
Run Code Online (Sandbox Code Playgroud)

否则,您可以将include=FALSE参数添加到代码块,然后\includegraphics手动创建指令.默认情况下,如果调用了Sweave文件test.Rnw,那么代码块生成的pdf文件的名称将是test-Q1b1.pdf.所以你可以这样做:

<<Q1b1,fig=true,include=false,echo=false>>=  
qqnorm(rnorm(100))
@

\begin{figure}[ht]
\caption{}
\begin{center}
\includegraphics[keepaspectratio=true,scale=0.1]{test-Q1b1.pdf}
\label{fig:1}
\end{center}
\end{figure}
Run Code Online (Sandbox Code Playgroud)

但是,我已经对您的示例进行了一些测试,但scale参数似乎对此处的数字没有任何影响.其他人喜欢这样angle做.