When using officedown::rdocx_document
in R Mardown, the Office Word output will include the plots as a .jpg image although my desire is to automatically include the plots of my R markdown in format .emf (Enhanched Metafile).
I know that with the function ggsave()
you can adapt the device to .emf like in this example:
plot(mtcars$mpg)
ggsave("plot.emf", width = 10, height = 6, scale = 1, device = {function(filename, ...) devEMF::emf(file = filename, ...)})
Is there a way to do a workaround ggsave
to change the device output of the plots in a RMarkdown (.Rmd) using officedown::rdocx_document as the output?
Here the answer to my own question after some research.
If you don't want to ggsave()
and then knitr::include_graphics()
every plot of your .Rmd in .emf (Enchanced Metafile) because there are a lot of them, then consider changing the graphic device of your .Rmd so that when it is exported to Word through the amazing package officedown (shout out to David Gohel) all the plots would be inserted in .emf extension that is more suitable for print publications than .png o .svg. Here the code workaround (is a simple change in your setup chunk but really makes the difference):
```{r setup, include=FALSE}
pacman::p_load("devEMF")
knitr::opts_chunk$set(echo = FALSE,
warning = FALSE,
message = FALSE,
dev = "emf",
fig.ext = "emf")
```
I hope it helps the community that uses officedown for Office Word Reports.