How do I group and/or force the location of nodes in a DiagrammeR graph in R?

106 views Asked by At

I'm using the DiagrammeR R package to try to create a flowchart that looks something like this. I've run into a couple hurdles. The first is that I can't figure out how to 'group' the nodes and draw a box around them, and the less important hurdle is that I don't know how to have the nodes in a specific order (at least on the top row). The current result is this.

My code is here:

library(DiagrammeR)
library(tidyverse)

test <- create_graph() %>% 
  add_nodes_from_table("data/tbm_nodes.csv", label_col = label) %>% 
  add_edges_from_table("data/tbm_edges.csv", from_col = from, to_col = to, from_to_map = id_external) %>% 
  set_node_attrs(shape, "box") %>% 
  set_node_attrs(fixedsize, "false")
  
render_graph(test, layout = "tree")

The nodes dataset has an income column with 'high' or 'low', as well as id and label columns, and the edges dataset has just the from and to information.

I've looked through the documentation pretty thoroughly for both the R package and graphviz (which DiagrammeR uses (I'm pretty sure? Unless I'm very mistaken)), but nothing has seemed to help. I've tried setting a group for each node based on income, but that didn't work. Neither did setting absolute position values with set_node_position(). The 'tree' layout is perfect except for the grouping and first row node order, but maybe I need to set each node position individually and not use 'tree'? This would be a non-ideal approach of course.

I'm not sure what else to try at this point, I'm wondering if what I want to do is even possible with DiagrammeR?

0

There are 0 answers