rich-iannone / DiagrammeR

Graph and network visualization using tabular data in R
https://rich-iannone.github.io/DiagrammeR/
Other
1.68k stars 247 forks source link

Integrate grViz figures into bookdown #344

Open dchiu911 opened 5 years ago

dchiu911 commented 5 years ago

I reviewed #256, #70, #207, #133 but couldn't quite find a solution.

A plot generated in a knitr chunk (e.g. by ggplot) gets saved as a figure with a filename that is passed from the chunk label, in _bookdown_files directory. The same is not done with grViz figures. To emulate this behaviour, one can do the following to both print and save a grViz figure

library(magrittr)
g <- DiagrammeR::grViz('digraph{a->b; c->a; c->b; c->d;}')
g

g %>%
  DiagrammeRsvg::export_svg() %>%
  charToRaw() %>%
  rsvg::rsvg_png("g.png")

Created on 2019-04-25 by the reprex package (v0.2.1)

But this does not programatically pass the chunk label to the png file name and put it in the same directory as the other saved figures.

pa0 commented 5 years ago

I think You have to add in text:

![](g.png)