I have used DiagrammeR for the visualization below. However, I would like to have the different node types organized under each other in columns, which only automatically happens with the yellow ones.
I tried using set_node_position for this purpose, but this does not have an effect on the rendered graph.
Here is my code:
graph <- create_graph()
graph <- add_nodes_from_table(graph = graph,
table = concepts_df,
label_col = name_english,
type_col = type)
graph <- add_edges_from_table(graph = graph,
table = links_df,
from_col = "sender",
to_col = "receiver",
from_to_map = "label")
graph <-
graph %>%
set_node_position(
node = 1,
x = 1, y = 1,
use_labels = TRUE) %>%
set_node_position(
node = 2,
x = 2, y = 2,
use_labels = TRUE)
graph_rendering <- graph
graph_rendering$nodes_df$fillcolor <- unlist(lapply(concepts_df$type,
function(type) switch(type,
"Target" = "#A0B7B4",
"Direct threat" = "#FCF2E1",
"Indirect factor" = "#EEE5CF",
"Biophysical stressor" = "#C7DDDA",
"Policy issue" = "#ECD2A4"
)))
graph_rendering$edges_df$color <- unlist(lapply(links_df$sign,
function(type) switch(type,
"+" = "darkseagreen",
"-" = "tomato",
"+/-" = "grey"
)))
graph_rendering$nodes_df$shape <- ifelse(concepts_df$type == "Target", "square","circle")
graph_rendering$nodes_df$fontcolor <- "black"
graph_rendering$global_attrs <- rbind(graph_rendering$global_attrs,
c("rankdir","LR","graph"),
c("ranksep","2 equally","graph"),
c("fontsize","14","node"),
c("arrowsize",1,"edge"))
graph_rendering$global_attrs[graph_rendering$global_attrs == "layout", 2] <- "dot"
graph_rendering$global_attrs[graph_rendering$global_attrs == "layout = neato"]
render_graph(graph_rendering)
How can I set the position of the nodes?