Knitting RMarkdown with ggvis to Word

2019-04-10 00:53发布

问题:

When I try to knit a RMarkdown document with ggvis plots to Word, I get the following message from Rstudio.

Error: Functions that produce HTML output found in document targeting docx output.
Please change the output type of this document to HTML.
Execution halted

Does there exist an elegant solution (without too much effort) to make this possible, perhaps using export_png and vg2png?

回答1:

Here is an example:

```{r setup, include=FALSE}
library(dplyr)
library(ggvis)
```

The following table looks fine...
As long as I don't include this plot below

```{r, echo=FALSE, include=FALSE}
p <- pressure %>%
  ggvis(x = ~temperature, y = ~pressure) %>%
  layer_bars()
export_png(p, file = "hoge.png")
```

![](hoge.png)

If you will use this frequently, you can define hook.



回答2:

  1. First go to Node JS Download page
  2. After instaling node.js, in terminal run:

    npm install vega