我一直在查看diagrammeR包(http://rich-iannone.github.io/DiagrammeR/)以在rMarkdown中生成图表。这在用HTML呈现文档时效果很好;现在我的问题是是否有可能将文档输出为MS Word文档?
例如,考虑一下:
---
title: "Test"
author: "Test"
date: "Monday, May 18, 2015"
output: html_document
---
```{r, echo=FALSE, warning=FALSE}
if (!require("DiagrammeR")) library("DiagrammeR")
```
Check out this diagram:
```{r, echo=FALSE, results='asis'}
DiagrammeR::grViz("
digraph rmarkdown {
node [shape = box ]
'A' -> 'B'
}
")
```
使用HTML作为输出格式就像一个魅力。但是,当我切换到MS Word时,我得到的只有:
Error: Functions that produce HTML output found in document targeting docx output.
Please change the output type of this document to HTML.
任何想法都会受到赞赏。
非常感谢,Philipp
答案 0 :(得分:2)
trelliscope
非常有用:https://github.com/tesseradata/trelliscope
安装http://phantomjs.org/download.html后, 您可以通过以下方式生成word doc文件:
---
title: "Test"
author: "Test"
date: "Monday, May 18, 2015"
output: word_document
---
```{r include=FALSE}
if (!require("DiagrammeR")) library("DiagrammeR")
library(trelliscope)
```
Check out this diagram:
```{r, include=FALSE}
p = DiagrammeR::grViz("
digraph rmarkdown {
node [shape = box ]
'A' -> 'B'
}
")
widgetThumbnail(p, paste0(getwd(), "/hoge.png"))
```
![](hoge.png)
这是截图。它看起来很完美:)