An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090414/3062857a/attachment-0001.pl>
using Sweave, how to save a plot in a given size
9 messages · Wolfgang Raffelsberger, Lore M, ONKELINX, Thierry +1 more
Hi I do somthing like:
\SweaveOpts{prefix.string=proj1}
<<label=fig1,fig=T,include=F,width=8, height=12>>=
plot(1:10)
@
\begin{figure}
\includegraphics {proj1-fig1} %% show
\label{..}
\end{figure}
Wolfgang
Lore M a ?crit :
Hi,
I'm trying to realise a repport with R and Latex (TeXnicCenter and Miktex for Windows) using Sweave().
I'd like to save my plots in a given size. How can I do that ? The code is :
\SweaveOpts{prefix.string = figs/plot, eps = FALSE, pdf = TRUE}
<<partI, echo=FALSE ,fig=TRUE, include=FALSE>>=
plotFunction()
@
\includepdf[pages=-]{figs/plot-partI}
When I use par(pin=c(width,height)), I get the plot with the right size but saved in a too big pdf page (7in x 7in, the default size of the window).
So I tried to change the size of the window with the command windows() but then, Sweave can't save the plot correctly.
Thanks everyone.
Lore.
_________________________________________________________________ ? Lancez-vous ! [[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.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Wolfgang Raffelsberger, PhD Laboratoire de BioInformatique et G?nomique Int?gratives CNRS UMR7104, IGBMC 1 rue Laurent Fries, 67404 Illkirch Strasbourg, France Tel (+33) 388 65 3300 Fax (+33) 388 65 3276 wolfgang.raffelsberger (at) igbmc.fr
1 day later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090415/a74bad80/attachment-0001.pl>
Dear Lore,
The easiest thing to do is to write a function that saves your plot to a file and generates the latex code.
<<label=fig1, fig=FALSE, result = tex>>=
pdf("fig1.pdf", width = wid, heigth = hei)
plot(1:10)
dev.off()
cat("\begin{figure}\")
cat("\includegraphics[width = ", wid, ", height = ", hei, "]{proj1-fig1}\"}
cat("\end{figure}")
@
HTH,
Thierry
----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
-----Oorspronkelijk bericht-----
Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Namens Lore M
Verzonden: woensdag 15 april 2009 13:46
Aan: wolfgang.raffelsberger at igbmc.fr; R Help
Onderwerp: Re: [R] using Sweave, how to save a plot in a given size
Yes it works, but I still have a problem.
The thing is that I know the dimensions of my plot but in the R code, not in the latex code. So I tried to do :
\SweaveOpts{prefix.string=proj1}
<<label=fig1,fig=T,include=F,width=\Sexpr{wid}, height=\Sexpr{hei}>>=
plot(1:10)
@
\begin{figure}
\includegraphics {proj1-fig1} %% show
\end{figure}
But Latex doen't find the value of "wid" and "hei" when it creates the chunk code. But in the Latex code, it works and I do have the right value for "wid" and "hei".
Lore.
Date: Tue, 14 Apr 2009 12:42:16 +0200
From: wraff at titus.u-strasbg.fr
To: tchibadou at hotmail.com
CC: r-help at r-project.org
Subject: Re: [R] using Sweave, how to save a plot in a given size
Hi I do somthing like:
\SweaveOpts{prefix.string=proj1}
<<label=fig1,fig=T,include=F,width=8, height=12>>=
plot(1:10)
@
\begin{figure}
\includegraphics {proj1-fig1} %% show
\label{..}
\end{figure}
Wolfgang
Lore M a ?crit :
Hi,
I'm trying to realise a repport with R and Latex (TeXnicCenter and Miktex for Windows) using Sweave().
I'd like to save my plots in a given size. How can I do that ? The code is :
\SweaveOpts{prefix.string = figs/plot, eps = FALSE, pdf = TRUE}
<<partI, echo=FALSE ,fig=TRUE, include=FALSE>>=
plotFunction()
@
\includepdf[pages=-]{figs/plot-partI}
When I use par(pin=c(width,height)), I get the plot with the right size but saved in a too big pdf page (7in x 7in, the default size of the window).
So I tried to change the size of the window with the command windows() but then, Sweave can't save the plot correctly.
Thanks everyone.
Lore.
_________________________________________________________________ ? Lancez-vous ! [[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.
-- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Wolfgang Raffelsberger, PhD Laboratoire de BioInformatique et G?nomique Int?gratives CNRS UMR7104, IGBMC 1 rue Laurent Fries, 67404 Illkirch Strasbourg, France Tel (+33) 388 65 3300 Fax (+33) 388 65 3276 wolfgang.raffelsberger (at) igbmc.fr
_________________________________________________________________ [[elided Hotmail spam]] Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090415/6fc6c9e2/attachment-0001.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090415/3f1e687c/attachment-0001.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090415/c7db1e8f/attachment-0001.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090415/0363d6d1/attachment-0001.pl>
Lo_Lo wrote:
I just want to add that I didn't have any overful box before I use :
<<label=fig1, fig=FALSE, results = tex>>=
pdf("fig1.pdf",
width = wid, heigth = hei)
plot(1:10)
plot(1:10)
dev.off()
cat("\\begin{figure}[h]")
cat("\\centering")
cat("\\multido{\i=1+1}{7}{\includegraphics[page=\i,width=1.5in, height =
1.5in]{images.pdf}}")
cat("\\end{figure}")
@
Here's a couple of pointers for using figures in Sweave that might help you
out.
1. Only one plot per figure chunk- Sweave gets confused if you use more than
one *high level* plotting command.
2. Don't call the pdf() function- the Sweave driver does this automatically
if you set pdf=T in the \SweaveOpts or the << >> code chunk header.
3. Don't use cat() to output the \begin{figure}, \end{figure},
\includegraphics, ect. These will end up in the wrong place.
From the look of your example, this is what you might want to include in
your .Rnw file:
\begin{figure}[h]
\centering
% Replace width and height with whatever dimensions you need. Leave them as
bare numbers
% i.e. 5 not 5in.
<<fig1,echo=F,fig=T,pdf=T,width=5,height=5>>=
plot(1:10)
@
% You can put a // here to cause the figures to separate onto two lines.
<<fig2,echo=F,fig=T,pdf=T,width=5,height=3>>=
plot(1:10)
@
% It is very important that all code chunks have different names! I.e.
<<fig1>>, <<fig2>> ect.
\end{figure}
The result of running Sweave on filename.Rnw will be:
\begin{figure}[h]
\centering
\includegraphics{filename-fig1}
\includegraphics{filename-fig2}
\end{figure}
Hope this helps!
-Charlie
-----
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
View this message in context: http://www.nabble.com/using-Sweave%2C-how-to-save-a-plot-in-a-given-size-tp23036715p23063594.html Sent from the R help mailing list archive at Nabble.com.