[R] Sweave: infelicities with lattice graphics

Claudia Beleites cbeleites at units.it
Thu Jul 15 23:59:09 CEST 2010


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



More information about the R-help mailing list