[R] Lattice and Beamer

Douglas Bates bates at stat.wisc.edu
Mon Jun 28 21:47:39 CEST 2010


On Mon, Jun 28, 2010 at 12:28 PM, Doran, Harold <HDoran at air.org> wrote:
> Two things I think are some of the best developments in statistics and production are the lattice package and the beamer class for presentation in Latex. One thing I have not become very good at is properly sizing my visuals to look good in a presentation.
>
> For instance, I have the following code that creates a nice plot (sorry, cannot provide reproducible data).
>
> bwplot(testedgrade~person_measure|gender + ethnicity, pfile, layout=c(2,5),
> main = 'Distribution of Person Measure by Grade\n Conditional on Gender and Ethnicity (Math)',
>                xlab = 'Grade')
>
> Now inside my latex document using the beamer class for presentation I have the following
>
> \begin{frame}
> \frametitle{Distribution of Person Parameters by Grade Conditional on Gender and Ethnicity}
> \begin{figure}[htb]
> \centering
> \fbox{\includegraphics[scale=.3]{personGenEthn.pdf}}
> \end{figure}
> \end{frame}
>
> I use the scale argument here. I do this totally randomly. I first start with scale=.5. Then, I create the document and look at it. If it seems to fit, I keep it. If it's too big, I resize it until it looks good. There must certainly be a much better way to size these for specific use with latex presentations.
>
> Any thoughts?


I think we have had this discussion before and I have tried to
convince you to use Sweave with beamer and lattice.:-)

A big advantage of Sweave is that you have the code that the generates
the figures in the LaTeX file and you don't allow the possibility of
losing track of PDF files containing the latest versions of figures.

In my preamble I have some lines like

\SweaveOpts{engine=R,eps=FALSE,pdf=TRUE,width=10,height=6.5,strip.white=all}
\SweaveOpts{include=TRUE}
\setkeys{Gin}{width=\textwidth}

Setting the default height and width of the PDF figure and the
inclusion width=\textwidth provides a default scaling that looks good
to me.  If I want a shorter figure that allows for text on the slide
then I set the height to a smaller value.  A full height version looks
like

\begin{frame}
  \frametitle{Plot of inverse canonical link for the Bernoulli distribution}
<<BernoulliinvLink,fig=TRUE,echo=FALSE>>=
linkinv <- function(eta) 1/(1+exp(-eta))
eta <- seq(-7,7,len = 701)
print(xyplot(linkinv(eta) ~ eta, type = c("g","l"),
             xlab = expression(eta),
             ylab = expression(mu == frac(1,1+exp(-eta)))))
@
\end{frame}


>
> Harold
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list