I've been exploring the possibilities of the DiagrammeR package in R to make flow charts and graphs in general. It seems quite nice, but I ran into a curious situation: the render_graph()
function produces wrong font color on the nodes and I can't understand why.
In the reproducible example below:
The node font color is by default set to "gray50" (line 12 in the global graph attributes below), but the font color is black when rendering with the render_graph()
function (see 1st image below).
It is, however, displayed properly when rendered with the generate_dot() |> grViz()
sequence of functions (see 2nd image).
I haven't spotted any other inaccuracies yet, but I can't rule them out.
I wonder, is this a bug or a feature? Does this mean I should not trust render_graph()
? And does anyone know why there is this discrepancy?
Thank you!
# Create a minimal graph with just 2 nodes and no edges
nodes <- DiagrammeR::create_node_df(2,label=c("a","b"))
graph <- DiagrammeR::create_graph(nodes_df=nodes,edges_df=NULL)
# Show its global attributes
graph |> DiagrammeR::get_global_graph_attr_info()
attr | value | attr_type | |
---|---|---|---|
1 | layout | neato | graph |
2 | outputorder | edgesfirst | graph |
3 | bgcolor | white | graph |
4 | fontname | Helvetica | node |
5 | fontsize | 10 | node |
6 | shape | circle | node |
7 | fixedsize | true | node |
8 | width | 0.5 | node |
9 | style | filled | node |
10 | fillcolor | aliceblue | node |
11 | color | gray70 | node |
12 | fontcolor | gray50 | node |
13 | fontname | Helvetica | edge |
14 | fontsize | 8 | edge |
15 | len | 1.5 | edge |
16 | color | gray80 | edge |
17 | arrowsize | 0.5 | edge |
# Render it with one method
graph |> DiagrammeR::render_graph()
Graph rendered with render_graph()
# Render it with another method
graph |> DiagrammeR::generate_dot() |> DiagrammeR::grViz()
render_graph
attempts to set a contrasting text color if not explicitly stated. The relevant part of the function isTo generate the same graph as the alternative method in the post, you can remove this section, overwriting the function. Insert internal
DiagrammeR
functions where needed using:::
.Then, both functions give the same result.