问题
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)
```
来源:https://stackoverflow.com/questions/25040873/rmarkdown-vector-graphics-for-knit-word