1

I'm attempting to KNIT rmarkdown to Word with ggvis, and getting the below error:

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

Below is reproducible code to try it out. I am using RStudio. If you comment the last line, it will work fine. If you don't, it will fail.

---
title: "TestWordOutput"
author: "John"
date: "August 20, 2015"
output: word_document
---

```{r}
library(ggvis)
summary(cars)

plot(cars)

ggvis(cars, ~speed, ~dist)
```

I have done some research, and the closest thing I've found is this post. However, the code in the answer doesn't work for me.

Any help would be greatly appreciated.

Community
  • 1
  • 1
John Tarr
  • 717
  • 1
  • 9
  • 21

1 Answers1

1

Read this: http://rpackages.ianhowson.com/cran/ggvis/man/export_png.html (or do ?export_png). Follow the instructions here to try to get those Vega/node.js utils to work (I couldn't now, but have in the past), then do something like:

---
title: "TestWordOutput"
author: "John"
date: "August 20, 2015"
output: word_document
---

```{r}
library(ggvis)
summary(cars)

plot(cars)

ggvis(cars, ~speed, ~dist) %>% export_png("mtcars.png")
```

![](mtcars.png)

And it should work for you. But, I'd stick with ggplot2 graphs if your target is Microsoft Word. They won't be interactive in Word and you can make super-awesome looking ggplot2 charts.

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • Thanks for the advice. I'm on a locked down machine, so installing node.js and then a package on top of that is probably more trouble than it is worth. The reason I've been trying to avoid ggplot2 is that I hear it can't do dual axis charts. – John Tarr Aug 21 '15 at 12:03
  • (some of us consider that A Good Thing :-) – hrbrmstr Aug 21 '15 at 12:50
  • 1
    So I've read, but I've yet to see a convincing reason why. Even in [this detailed explanation](https://www.perceptualedge.com/articles/visual_business_intelligence/dual-scaled_axes.pdf) I feel his first plot goes against his point. In that plot, the first thing I notice is that revenue continued to climb, despite a decrease in units sold from the prior month. That's an interesting point that I don't feel is as clear in a panel plot. I grant that they can be mis-used, but that doesn't seem good enough reason to throw them out. – John Tarr Aug 21 '15 at 14:12