## 17.1 Basic diagrams

DiagrammeR provides methods to build graphs for a number of different graphing languages.

R Studio provides native support for Graphviz (.gv) and mermaid (.mmd) files. Using files of these types in RStudio provides the advantage of syntax coloring and allowing a quick preview of the diagram. For example, we can make a simple flowchart with the following code:

DiagrammeR::grViz("digraph {

graph [layout = dot, rankdir = LR]

node [shape = rectangle]
rec1 [label = 'Step 1']
rec2 [label = 'Step 2']
rec3 [label =  'Step 3']
rec4 [label = 'Step 4']

# edge definitions with the node IDs
rec1 -> rec2 -> rec3 -> rec4
}",
height = 200)

FIGURE 17.1: A basic graphic using DiagrammeR

There are extensive controls which can be used to control the shape of nodes, colours, line types and add additional parameters.