Flow charts in R using DiagrammeR

This is really short but I was really excited to share this info. When I was trying to find a way to create a flow chart in R I started with a few different packages that required a huge amount of prep work  before plotting a flow chart, and then I found the magical DiagrammeR  package.

It really should be more difficult:

library(DiagrammeR)
DiagrammeR("graph LR;
           A-->B;
           B-->C;
           B-->D")

Creates this:

Pretty cool, Right?

By assigning each letter you can update the flow direction, text and shape

DiagrammeR("graph TB;
    A(Rounded)-->B[Squared];
    B---C{Rhombus!};
    C-->D>flag shape];
    C-->E((Circle));")

Creates this:

Notice that after graph it says TB (top bottom) vs LR, Text can be added, type of brackets dictate the output shape and — vs –> makes a line instead of an arrow.

This package is really impressive and the documentation has some  very interesting images of very complicated graphs and flow charts, this image was made using the example provided in the package instructions.

Leave a Reply