我正在尝试向 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.
我可以在 word 中重新调整情节的大小,但不必这样做会很好。
有没有办法在 .rmd 文件中设置页面大小和边距?
有没有办法确保绘图保持在指定的大小,即使它们不适合创建的 Word 文档的边距?
最佳答案
您可以重做 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
关于r knit word 文档图自动重新调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29333440/