TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using LyX with the Sweave module to generate some R figures within a document. I can't seem to get the figures to be smaller, and they tend to take up half a page which is far too large. I have tried:

 <<echo=F, fig=T, width=0.5, height=0.5>>=

bit it throws an error. Putting any value greater than 1 for width and height make my figure lines thick and font huge but the amount of space it takes up is essentially the same.

So is there anyway to make the output figures smaller?

share|improve this question

migrated from stackoverflow.com Mar 7 '12 at 16:37

This question came from our site for professional and enthusiast programmers.

see Xu Wang's answer below; Sweave does not support that directly -- people always tell you to use \setkeys{Gin} for Sweave, but it is really a bad trick in my eyes so I just added a new option out.width in knitr (see motivation of knitr: github.com/yihui/knitr#readme and documentation of options yihui.name/knitr/options) – Yihui Mar 7 '12 at 7:45

Which version of LyX are you using? If you are using 2.0.3 (the newest stable version), you can use knitr which is more flexible, in my opinion. Note that you have to have knitr installed in R, which you can do by install.packages('knitr'). Then, in LyX, for the module instead of Sweave choose Rnw (knitr).

Once you have knitr installed in R and loaded in LyX, this works well for me:

<<chunk_name, fig.width=6.5, fig.height=4, background=NA>>=
share|improve this answer
Thanks. In fact the most important option to this question is out.width, e.g. out.width='.8\\linewidth'. BTW, you do not need to quote NA, and echo=FALSE is irrelevant here. It might also worth mentioning yihui.name/knitr/demo/lyx since there is a screenshot. – Yihui Mar 7 '12 at 7:48
@Yihui thank you for the comments! I should have known that you would see this but I wasn't sure. Really you should give the answer because your answer will be more clear. – Xu Wang Mar 7 '12 at 9:06
You can edit yours too :) – Yihui Mar 7 '12 at 19:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.