[R] change default output size when using Sweave
Franzini, Gabriele [Nervianoms]
Gabriele.Franzini at nervianoms.com
Thu Apr 9 13:24:43 CEST 2009
Hi,
I had a similar problem, and I took the direction of squeezing the
output into a minipage, e.g.:
...
@
\begin{minipage}[c]{0.6\textwidth}
<<fig=TRUE, echo=FALSE>>=
plot(...)
abline(...)
@
\end{minipage}
...
HTH,
Gabriele Franzini
ICT Applications Manager
Nerviano Medical Sciences SRL
Nerviano Italy
-----Original Message-----
From: Mark Heckmann [mailto:mark.heckmann at gmx.de]
Sent: 08 April 2009 10:31
To: 'Duncan Murdoch'
Cc: r-help at r-project.org
Subject: Re: [R] change default output size when using Sweave
Dear Duncan,
Thanks for the reply. This works, but unfortunately I need a different
solution.
My script is supposed to run completely automated and the graphics I
produce vary in size each time I run the script. But I want the graphics
to be fitted to my .pdf output without specifying the height argument
manually each time.
That is why I do not want a fixed height as a code chunk argument.
Actually I do not know if it is possible to have a variable placed in a
code chunk header. I tried the following which does not work:
<<>>=
size <- 3
@
<<fig=TRUE, echo=TRUE, height=size>>=
pushViewport(viewport(height = unit(80, "mm")))
grid.rect()
grid.text("I want this viewport to be the whole output size")
popViewport()
@
So still I face the problem to have Sweave generate a .pdf graphic that
is just as big I want it to be.
In the Sweave Docu paragraph A.9 I discovered something I use as a
workaround. I produce the .pdf output manually (where I can control the
size) and add each graphic to LaTex manually as well.
<<results=tex, echo=FALSE>>=
for (i in 1){
file=paste("myfile", i, ".pdf", sep="")
pdf(file=file, paper="special", width=6, height=3)
pushViewport(viewport(height = unit(5, "inches")))
grid.rect()
grid.text("I want this viewport to be the whole output size")
popViewport()dev.off()
cat("\\includegraphics{", file, "}\n\n", sep="") } @
I use parenthesis around the code as it prints out something I do not
want if no parenthesis are used (I use Windows).
I am not too happy with the solution. I would prefer a more
straightforward approach to define the size of the output graphic. I
wonder if there are some Sweave settings that can be modified.
In the Sweave manual (A.11) I found the following to customize the par
settings for each figure:
options(SweaveHooks=list(fig=function() par(bg="red", fg="blue")))
I wonder if something similar could be done changing the size of the
default output device (pdf or eps) for each figure like
>pdf.options(height=2) or similar (it seems that this does not work)?
I suppose this type of graphic customization is quite a common issue
when producing automated customized output/reports using R and Sweave
but I haven't found anything concerning this topic yet.
So I would be really glad if someone knows a solution.
TIA, Mark
More information about the R-help
mailing list