r编织word文档图自动重新调整大小

Dav*_*son 5 r rstudio knitr r-markdown

我想在word文档中添加一个图表.我希望该图可以在页面大小设置为合法且边距较窄时最大化可用区域.我可以设置fig.width和fig.height,但似乎图表会自动重新调整大小以适应具有正常边距的默认页面大小(字母).

这是一个示例.rmd文件,它产生相同的结果:

---
title: "plot-resize"
output: word_document
---

Plot with the height set to 3" and the width to 7.5":

```{r, echo = FALSE, fig.height=3, fig.width=7.5, warning=FALSE, message=FALSE}
plot(cars)
```

However when the word document is created the image is automatically 
re-sized to 79% of this. 
Run Code Online (Sandbox Code Playgroud)

我可以用字重新调整情节的大小,但不必这样做会很好.

有没有办法在.rmd文件中设置页面大小和边距?

有没有办法确保图表保持指定的大小,即使它们不适合创建的word文档的边距?

Jam*_*ant 5

您可以重做MS Word模板文件-请参阅http://rmarkdown.rstudio.com/articles_docx.html-您必须将正在使用的MS Word模板文件中的边距更改为窄(0.5英寸)(在布局下)然后,右键单击图形并选择大小和位置,然后将缩放高度和宽度调整为100%,然后您必须保存模板文件(不要忘记关闭它!),然后添加这到您的YAML:

title: "plot-resize"
output:
  word_document:
    reference_docx: mynew_template.docx
Run Code Online (Sandbox Code Playgroud)