Skip to content
Prev 317510 / 398502 Next

sweave question

Other people in this thread have explained the rule of double
backslashes. I just want to add one more comment:

That clever solution was in 2009 when knitr has not come out, and I
have used this picture several times to show how much I dislike it:
http://yihui.name/en/2012/06/enjoyable-reproducible-research/

With knitr, you can easily write your big code chunk (with lots of
"cats" jumping around) in a much more compact way:

<<figthree, fig.pos="ht!", fig.align="center", out.width="5in",
out.height="5in", fig.cap="The resulting unpruned regression tree of
the California real estate data">>=
plot(cal.tree,uniform=TRUE,compress=TRUE,margin=0.0)
text(cal.tree, all=TRUE,fheight=1.0,fwidth=1.0)
@

Note the number "5" alone is not a legal LaTeX length; you should add
the unit such as "5in" or "5cm", etc. This chunk in knitr will
generate everything for you:

- the figure environment
- center the figure
- add the figure position ht!
- add the figure caption
- add figure width and height
- add the figure label fig:figthree

You, as the author, only write the R code (instead of both R and
LaTeX); other people, as the readers, only see the R code. Everything
else should go behind the scene.

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
On Wed, Feb 13, 2013 at 4:59 PM, Mark Leeds <markleeds2 at gmail.com> wrote: