Scaling plots in Rmd via out.width
<p>I am producing a Rmd document that also includes some plots.  It should export to both, otd and pdf.  Some of the figures should be small enough to fit two of them next to each other in the resulting odt.</p>

<p>I knit the document via</p>

<pre><code>Rscript -e "require(knitr); require(markdown); knit('Test_Markdown.Rmd', 'Test_Markdown.md')"
</code></pre>

<p>In the Rmd there is a plot that looks like this:</p>

<pre><code>```{r plottestnormal, fig.path = ".", fig.width = 6, fig.height = 6, dpi = 300, dev = "png", dev.args = list(type = "cairo")}
plot(1:10, 1:10)
```
</code></pre>

<p>I would like the plot to be half size -- but scaled!</p>

<p>This gets the size correct, but not the scaling:</p>

<pre><code>```{r plottestsmall, fig.path = ".", fig.width = 3, fig.height = 3, dpi = 600, dev = "png", dev.args = list(type = "cairo")}
plot(1:10, 1:10)
```
</code></pre>

<p>This as I understand from <a href="http://yihui.name/knitr/options/" rel="nofollow">the opiton description</a> the following should do what I mean, but it does not 'work'.</p>

<pre><code>```{r plottestscaled, fig.path = ".", fig.width = 6, fig.height = 6, out.width = 3, out.height = 3, dpi = 300, dev = "png", dev.args = list(type = "cairo")}
plot(1:10, 1:10)
```
</code></pre>

<p>What happens is that this produces an html img tag in the generated *md file:</p>

<pre><code>&lt;img src=".plottestscaled-1.png" title="plot of chunk plottestscaled" alt="plot of chunk plottestscaled" width="3" height="3" /&gt;
</code></pre>

<p>And that does not show in either pdf nor odt when compiled with</p>

<pre><code>pandoc -f markdown "Test_Markdown.md" -o "Test_Markdown.odt"

pandoc -t latex "Test_Markdown.md" -o "Test_Markdown.pdf"
</code></pre>

<p>And I have seen <a href="https://github.com/yihui/knitr/issues/528" rel="nofollow">this issue</a> which does not help me further.</p>

<p>What am I missing?</p>

<p>EDIT:</p>

<p>Thanks to @Yihui this now works for LaTeX-> pdf and (presumably -- untested) for html.</p>

<p>Am I right, that <code>out.width</code> and <code>out.height</code> are not supported for <code>*.odt</code> or <code>*.docx</code> export?</p>

<p>If they are, what might be the reason that they do not work for me?</p>

<p>If they are not, how can I achieve the same effect (scaled plots) in <code>*.odt</code>?</p>

<p>(I would like to export to <code>pdf</code> and <code>odt</code>, so any solution would ideally cover (at least) these two simultaneously.)</p>

<p>Here is a complete doc that shows my problem when processed via <code>rmarkdown::render("Test_Markdown.Rmd", "all")</code>.</p>

<pre><code>---
title: Scale plot in Rmd
output:
    pdf_document:
        latex_engine: xelatex
    odt_document:
        keep_md: true
---

```{r plottestscaled, fig.path = "./", fig.width = 6, fig.height = 6, out.width = "3in", out.height = "3in", dpi = 300, dev = "png", dev.args = list(type = "cairo")}
plot(1:10, 1:10)
```
</code></pre>

<p>EDIT2:</p>

<p>My 'best' solution so far is, to disable the scaling in the <code>odt</code> output and to manually rescale the plots in office.  Not very reproducible, though....</p>

<pre><code>```{r plottestscaled, fig.path = "./", fig.width = 6, fig.height = 6, out.width=switch(opts_knit$get("rmarkdown.pandoc.to"), latex = "3in", NULL), out.height=switch(opts_knit$get("rmarkdown.pandoc.to"), latex = "3in", NULL), dpi = 300, dev = "png", dev.args = list(type = "cairo")}
plot(1:10, 1:10)
</code></pre>