Skip to content

Commit 4a26395

Browse files
committed
screenshot DiagrammeR
1 parent 50936df commit 4a26395

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

04-content.Rmd

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ While there are several different packages available for R, we will only briefly
575575

576576
The RStudio IDE provides native support for Graphviz (`.gv`) and mermaid (`.mmd`) files. Editing these types of files in RStudio has the advantage of syntax highlighting. RStudio also allows you to preview the diagrams by clicking the "Preview" button on the toolbar. Figure \@ref(fig:diagram-profit) is a simple flowchart example that has four rectangles representing four steps, generated by the code below:
577577

578-
```{r diagram-profit, fig.align='center', fig.cap="A diagram showing a programmer's daydream.", fig.dim=c(3, 6), out.width="100%"}
578+
```r
579579
DiagrammeR::grViz("digraph {
580580
graph [layout = dot, rankdir = TB]
581581
@@ -591,13 +591,17 @@ DiagrammeR::grViz("digraph {
591591
height = 500)
592592
```
593593

594+
```{r diagram-profit, echo=FALSE, fig.align='center', fig.cap="A diagram showing a programmer's daydream.", out.width="100%"}
595+
knitr::include_graphics('images/diagram-profit.jpg', dpi = NA)
596+
```
597+
594598
There are extensive controls that can be used to define the shape of nodes, colors, line types, and add additional parameters.
595599

596600
### Adding parameters to plots
597601

598602
Graphviz substitution allows for mixing R expressions into a Graphviz graph specification, without sacrificing readability. If you specify a substitution with `@@`, you must ensure there is a valid R expression for that substitution. The expressions are placed as footnotes and their evaluations must result in an R vector object. The `@@` notation is immediately followed by a number, and that number should correspond to the number of the R expression footnote. Figure \@ref(fig:diagram-params) shows an example of embedding and evaluating R code in the diagram.
599603

600-
```{r diagram-params, fig.cap="A diagram using parameters input from R.", fig.dim=c(6, 1), out.width="100%", crop=TRUE}
604+
```r
601605
DiagrammeR::grViz("
602606
digraph graph2 {
603607
@@ -621,6 +625,10 @@ DiagrammeR::grViz("
621625
height = 100)
622626
```
623627

628+
```{r diagram-params, echo=FALSE, fig.cap="A diagram using parameters input from R.", out.width="100%"}
629+
knitr::include_graphics('images/diagram-params.jpg', dpi = NA)
630+
```
631+
624632
### Other packages for making diagrams
625633

626634
You may also check out these packages for creating diagrams: **nomnoml** [@R-nomnoml], **diagram** [@R-diagram], **dagitty** [@R-dagitty], **ggdag** [@R-ggdag], and **plantuml** (https://github.com/rkrug/plantuml).

images/diagram-params.jpg

24.2 KB
Loading

images/diagram-profit.jpg

22.5 KB
Loading

0 commit comments

Comments
 (0)