gpt4 book ai didi

r - 用 gridSVG 编织

转载 作者:行者123 更新时间:2023-12-04 12:38:22 26 4
gpt4 key购买 nike

有人在 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
```

当我点击“Knitr HTML”时,我得到:
pandoc.exe: Could not find data file
AnalysisReport_files/figure-html/unnamed-chunk-61.svg pandoc document conversion failed

gridsvg 似乎没有生成 svg 文件。我在互联网上搜索过,但没有找到任何在 knitr 中使用 gridSVG 的例子。

我应该如何修改代码? (P.S. 由于 windows 下的渲染质量,我不想使用默认的 'svg' 设备)

谢谢!

最佳答案

因为 gridSVG::gridsvg()不是标准的 R 图形设备,您不能使用 dev 中的块选项针织 .目前唯一的方法是手动保存绘图,并使用块 Hook 将绘图写入您的输出(请参阅 knitr graphics manual )。下面是一个例子:

---
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

查看 http://rpubs.com/yihui/knitr-gridsvg 处的输出

关于r - 用 gridSVG 编织,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23852753/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com