I have the following R code
<<Q1b1, fig=TRUE>>=
qqnorm(resid(model1), main=NULL)
@
and I would like to add the option [keepaspectratio=true, scale = 0.75] to the \includegraphics{} call so that the above R code chunk generates
\begin{figure}[ht]
\caption{}
\begin{center}
\includegraphics[keepaspectratio=true, scale = 0.75]{filename.pdf}
\label{fig:1}
\end{center}
\end{figure}
I know you can specify the width and height using \SweaveOpt{width=x, height=y} but I want to specify the scale and have it keep the aspect ratio of the figure when it's generated.
Is there an easy way to do this?
Thanks
You can set the width for every figure in your Sweave document with \setkeys{Gin}
instruction. For example, the following in the preamble of your document makes every figure width 80% of the text width on your page :
\setkeys{Gin}{width=0.8\textwidth}
Otherwise you can add the include=FALSE
argument to your code chunk and then create the \includegraphics
instruction manually. By default, if your Sweave file is called test.Rnw
, then the name of the pdf file generated by the code chunk will be test-Q1b1.pdf
. So you can do something like :
<<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}
However, I've made some tests on your example but the scale
parameter doesn't seem to have any effect on the figure here. Others like angle
do, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With