Dear Yihui,

thanks a lot for your kind reply. Your solution is very elegant and
versatile.
However, there is a point that is obscure to me and I didn't manage to
fully understand them after looking at the Knitr manual and graphic manual.
The issue concerns the hook:

*knit_hooks$set(par = function(before, options, envir) {
  if (before) par(mar = c(4, 4, .1, .1))
})*

why do you set par as a function?
moreover, below you write:

*par(bg=rgb(runif(1), runif(1), runif(1)))*

does this mean that* before = rgb(runif(1))*;* options = runif(1)*
and*envir = runif(1)
*?

and what does this produce? I don't understand what's going on, can you
please help me or address me to some documentation?

thanks in advance for your kind help,
f.











On 8 January 2013 18:03, Yihui Xie <x...@yihui.name> wrote:

> All you mentioned are possible; knitr has very comprehensive support
> to figures in LaTeX, and what you want in this case is subfigures
> (\usepackage{subfig}); here is an example:
>
> https://github.com/yihui/knitr-examples/blob/master/067-graphics-options.Rnw
> (search for 'fig.subcap' for the relevant chunk)
>
> And here is a preview: http://i.imgur.com/4lKpw.png
>
> Regards,
> Yihui
> --
> Yihui Xie <xieyi...@gmail.com>
> Phone: 515-294-2465 Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA
>
>
> On Tue, Jan 8, 2013 at 4:17 AM, Francesco Sarracino
> <f.sarrac...@gmail.com> wrote:
> > Dear R helpers,
> >
> > I am using knitr to run analysis with R and edit my document with Latex.
> I
> > am wondering whether there is a way to include 2 or more pictures per
> chunk
> > and being able to refer them in the text independently and eventually
> > whether it is possible to give them different captions. Let me give you
> an
> > example.Rnw:
> >
> > \documentclass{article}
> > \title{Example}
> > \author{FS}
> > \begin{document}
> > \maketitle
> >
> > I put some text here. I want  to plot to charts in the same figure and
> > label them independently.
> > <<stat, echo = FALSE, results = 'hide'>>=
> > ii <- 2000:2011
> > xx <- rnorm(12,0,1)
> > yy <- rnorm(12,0,1)
> > pm <- data.frame(ii,zz,yy
> > @
> >
> > Now I generate the two pictures and put them into the same chunk with the
> > option out.width set to .49 so that knitr places the two charts side by
> > side:
> > <<fig:example, echo = FALSE, out.width=".49\\linewidth", fig.cap="this is
> > an example>>=
> > plot(ii,xx, type = "l")
> > plot(ii,yy, type = "l", lty = 2)
> > @
> >
> > Finally, I want the reader to look at the figure on the left.
> > \end{document}
> >
> > How can I do this? If I refer to  \ref{fig:example} I will get the number
> > of the figure, but of the chart on the left.
> > Eventually, is it possible to have separate captions for each chart?
> > Thanks in advance for your kind help,
> > f.
> >
> >
> > --
> > Francesco Sarracino, Ph.D.
> > https://sites.google.com/site/fsarracino/
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@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.
>



-- 
Francesco Sarracino, Ph.D.
https://sites.google.com/site/fsarracino/

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to