9

When using rmarkdown with knitr in Rstudio to knit a Microsoft Word document, the graphics generally look crappy because the usual vector graphics formats, such as PDF are not supported in Microsoft Word.

Fortunately, the devEMF package in R generates the microsoft vector format EMF, and I almost have this working for my rmarkdown application. The problem is that my image is showing up way too small. How can I control the image size?

I've tried the standard things below:

---
title: "Plot size trouble demo"
author: "for stackoverflow"
output: word_document
---

Here I include graphics in a word document using the `emf` printing device.

```{r dev = 'emf', fig.ext = 'emf'}
require(devEMF)
plot(1:10, 1:10)

```

The plot is small, so I try to make it bigger with the `fig.height` and fig.width` options:

```{r dev='emf', fig.ext='emf', fig.height=10, fig.width=10}
require(devEMF)
plot(1:10, 1:10)

```

The plot region stayed the same size, and now I have super-small labels and points!

Finally, I try to use the `out.width` and `out.height` options to rescale the figure to a different size, but this produces nothing at all:

```{r dev='emf', fig.ext='emf', fig.height=10, fig.width=10, out.width = '5in', out.height= '5in'}
require(devEMF)
plot(1:10, 1:10)

```

Update: I noticed here that rmarkdown supports win.metafile, but the following also produces nothing:

```{r dev = 'win.metafile', out.width = '5in', out.height= '5in'}
plot(1:10, 1:10)
```
zkurtz
  • 3,230
  • 7
  • 28
  • 64
  • 1
    (Stylistic note: not literally every `word` remotely related to `code` needs a `code` `tag`. "PDF" and "EMF" are file extensions; by "Word" you presumably mean Microsoft Word.) – Jongware Jul 30 '14 at 15:48
  • 2
    I guess you should not use out.width/out.height. Sorry I do not have time to explain the technical details here. – Yihui Xie Aug 03 '14 at 19:18
  • Have you tried using a template file, as is suggested [here](https://stackoverflow.com/questions/29333440/r-knit-word-document-plots-automatically-re-sized)? – Peter May 03 '18 at 21:19

0 Answers0