Dear David,

you can use Gin:

\setkeys{Gin}{width=0.5\linewidth}

just before the chunk that actually produces the figure.



and, cool, I hadn't realized, that

<<fig = TRUE, echo = FALSE>>=
print (
<<chunk-with-lattice-function>>
       )
@

works.

with {} inside the print there can be even more than one statement in the chunk-with-lattice-function. However, that's not a good idea. There may be surprises due to the question how often the chunk-with-lattice-function is actually executed.

Claudia

I have wondered about this too.  The approach I use isn't pretty but does
have a couple of advantages - there is only one set of code to run and I
have control over the figure size.

The first part of the code below is what is shown in the document (but not
run), and the second part actually runs the code and makes the plot.

<<no2hist, eval=FALSE>>=
hist(mydata$no2)
<<no2hist1, echo = FALSE, results=hide>>=
pdf("no2hist.pdf")
<<no2hist>>
dev.off()
@
\begin{figure}
     \centering
     \includegraphics[width=0.5\textwidth]{no2hist}
     \caption{The caption.}
        \label{fig:hist}
\end{figure}

I'd be interested to know if there are neater ways of doing this.

Regards,

David

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to