{r setup, include=FALSE} knitr::opts_chunk$set(eval = FALSE) # 保存成图片的方式
对于 github_document等方式,需要静态图片,这里 参考cran 提供解决方案
{r eval=F} library(vtree) FakeDataFig <- vtree(FakeData,"Severity Sex",horiz=FALSE) grVizToPNG(FakeDataFig)
生成时间有点长。
{r} knitr::include_graphics('FakeDataFig.png')
vtreeuses theDiagrammeRpackage (which in turn is built on the open source graph visualization software,Graphviz).
grVizToPNGThe name of the graphics file (example1.png) is automatically derived from the name of the object (
example1).
实现方式 js$\to$svg$\to$png
这是解决方式
{r} function (g, width = 3000, folder = ".") { argname <- sapply(as.list(substitute({ g })[-1]), deparse) message <- utils::capture.output(svg <- DiagrammeRsvg::export_svg(g)) result <- rsvg::rsvg_png(charToRaw(svg), paste0(folder, "/", argname, ".png"), width = width) invisible(NULL) }
双向箭头
a -> b [dir=both] 参考Github Issue 252