r knit word document plots automatically re-sized

…衆ロ難τιáo~ 提交于 2019-12-10 14:33:59

问题


I am trying to add a plot to a word document. I would like the plot to maximize the area available when the page size is set to legal with narrow margins. I can set the fig.width and fig.height but it seems the plots get automatically re-sized to fit the default page size (letter) with normal margins.

Here is a sample .rmd file that produces the same results:

---
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. 

I can re-size the plot in word, but it would be nice to not have to.

Is there a way to set the page size and margins in the .rmd file?

Is there a way to ensure that the plots stay at the specified size even if they do not fit within the margins of the created word document?


回答1:


You can redo the MS Word template file - see http://rmarkdown.rstudio.com/articles_docx.html - you would have to change your margins to narrow (0.5") in the MS Word template file you are using (Under the Layout ribbon). Then, right click on the figure and select size and position, and then adjust scale height and width to 100%. You would then have to save your template file (and don't forget to close it!) and then add this to your YAML:

title: "plot-resize"
output:
  word_document:
    reference_docx: mynew_template.docx


来源:https://stackoverflow.com/questions/29333440/r-knit-word-document-plots-automatically-re-sized

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!