[Tex/LaTex] How to get correct dimensions for a ggplot2 plot in beamer

beamerrsweave

I have a beamer presentation made with Sweave that I'm preparing and was wanting to place some ggplot2 graphs in but the aspect ratio does not seem to come out correct. This is what is in my Rnw file.

\begin{frame}[containsverbatim]
\frametitle{Basic Workflow}\begin{itemize}
\item Start R (Start > All Programs > R > R x64 2.12.0 )\\
\item Load Packages
<<>>=
library(ggplot2)
library(MASS)
@
\item Load Data
<<>>=
data(iris) # or read.csv/read.table/etc.
head(iris[,3:5],n=3)
@
\item Graph Data
<<>>=
qplot(Petal.Length,Petal.Width,color=Species, data=iris)->p
@
\end{itemize}\end{frame}
\begin{frame}{Basic Workflow, Cont.}
<<fig=T,echo=F>>=
show(p)
@
\end{frame}

what comes out is a graph with the bottom cut off that takes up the left half of the page.

Best Answer

I find this a big pain. I have arrived at doing something like

% one-column
\SweaveOpts{height=5,width=8,echo=FALSE}
\setkeys{Gin}{width=4in}

% two-column
\SweaveOpts{echo=FALSE,height=5,width=5}
\setkeys{Gin}{width=2.25in}

Unfortunately, I don't know of a nice way to incorporate this into a LaTeX command; if I pack these into \onecolumnfig{} or \twocolumnfig{} LaTeX macros, Sweave doesn't see them (because they don't get expanded until after Sweave has processed the file).

Duncan Murdoch has provided various bits of useful information on this topic on the R list:

here and here, for example (results of googling "murdoch sweave setkey")

etc.

edit: the answer now, I think, is "use knitr" instead ( http://yihui.name/knitr/ ) -- it allows an out.width="0.8\\textwidth" (for example) specification in the chunk options.