有没有人在Knitr中使用gridSVG?我发现包"gridSVG"提供了一个名为"gridsvg"的设备,我编写了如下代码.
```{r message=FALSE, echo=FALSE, warning=FALSE, results='hide', dev='gridsvg', fig.ext='svg'}
analysis.runner.result.plot(result, score.table, info.table) # which produces a gpplot
```
Run Code Online (Sandbox Code Playgroud)
当我点击"Knitr HTML"时,我得到了:
pandoc.exe: Could not find data file
AnalysisReport_files/figure-html/unnamed-chunk-61.svg pandoc document conversion failed
Run Code Online (Sandbox Code Playgroud)
似乎gridsvg没有生成svg文件.我搜索过互联网但未能找到任何在knitr中使用gridSVG的例子.
我该如何修改代码?(PS由于windows下的渲染质量,我不想使用默认的'svg'设备)
谢谢!
因为gridSVG::gridsvg()不是标准的R图形设备,所以不能dev在knitr中使用chunk选项.目前唯一的方法是手动保存图形,并使用块钩将图形写入输出(参见knitr图形手册).这是一个例子:
---
title: Save plots using gridSVG and knitr
author: Yihui Xie
output:
html_document: default
---
Set up a chunk hook for manually saved plots.
```{r setup}
library(knitr)
knit_hooks$set(custom.plot = hook_plot_custom)
```
A single plot.
```{r test-a, fig.keep='none', fig.ext='svg', custom.plot=TRUE}
library(ggplot2)
qplot(speed, dist, data = cars)
gridSVG::grid.export(fig_path('.svg'))
```
Multiple plots.
```{r test-b, fig.keep='none', fig.ext='svg', custom.plot=TRUE, fig.num=2, message=FALSE}
library(ggplot2)
p = qplot(speed, dist, data = cars)
p + geom_smooth()
gridSVG::grid.export(fig_path('svg', number = 1))
p + geom_jitter()
gridSVG::grid.export(fig_path('svg', number = 2))
```
See the source document of this post at
http://stackoverflow.com/q/23852753/559676
Run Code Online (Sandbox Code Playgroud)
请参阅http://rpubs.com/yihui/knitr-gridsvg上的输出
| 归档时间: |
|
| 查看次数: |
582 次 |
| 最近记录: |