[R] getting "small" graphs with Sweave using Rnews.sty

Duncan Murdoch murdoch at stats.uwo.ca
Tue Nov 4 12:01:58 CET 2008

Jeff Hamann wrote:
> I'm sorry for having to post this, but I can't seem to find any 
> solutions to this, which seems pretty simple, but then again...
> I've started playing with the example r news project and wanted to start 
> adding some graphs, but replacing:
> \begin{figure}
> \vspace*{.1in}
> \framebox[\textwidth]{\hfill \raisebox{-.45in}{\rule{0in}{1in}}
>                        A graph goes here \hfill}
> \caption{\label{figure:onecolfig}
> A normal figure only occupies one column.}
> \end{figure}
> yields a an empty box, which is good, with the following:
> \begin{figure}
> \vspace*{.1in}
> <<fig=true,echo=false>>=
> plot( rnorm( 100 ) )
> @
> \caption{A normal figure only occupies one column.}
> \label{figure:onecolfig}
> \end{figure}
> which isn't good, or at least yields a "normal sized" graph that starts 
> in the second column, when I run Sweave( "yourarticle.rnw" ) and the 
> pdflatex wrapper
> Is it possible, to get a "small" graphic this way, or should I write
> out a temp graph as a pdf and include the graphic by constructing the
> statement using Sweave?
There are two ways to control the size of an Sweave graph:  by telling R 
the size you want, and by telling LaTeX how big to make it when you 
include it.

You tell R the size by using <<fig=true, width=w, height=h>>= (with w 
and h being numbers in units of inches).  You tell LaTeX
(assuming you're using the graphicx package) by using 
\setkeys{Gin}{width=w} (or maybe you'd want to set the height, but I 
usually just set the width and
let LaTeX scale the height accordingly).  The w here is a LaTeX measure 
such as \textwidth or 4in or whatever you like.

I find the font choices in R look a little bit too large if I tell R the 
actual size I want, so I generally use both: tell R I want the figure 
larger than I really want it, and then tell
LaTeX to shrink it to fit.

Duncan Murdoch
> Thanks for any advice,
> Jeff.
> ------------------------------------------------------------------------
> ______________________________________________
> 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