I am currently trying to create a flowchart using DiagrammeR
library(DiagrammeR)
grViz("
digraph g {
subgraph cluster_0 {
style=filled;
color=lightgrey;
label= To_Accrue
node [shape = rectangle, style = filled, fillcolor = Linen]
A
B
C
A->B->C
}
subgraph cluster_1 {
style=filled;
color=crimson;
label= Y
node [style=filled,color=blue, shape=folder]
1
2
3
1->2->3
}
}
")
Please refer to the link File to see what it currently generates (Tab-Sheet1). I was wondering if there is a way to achieve the desired output (Tab-Desired Output).
Thank you in advance.
The trick here is to use a blank node (called bnode here), groups (g1 in this example), and ranks (rank=same ...) to force the positioning and appearance you want. Nodes with the same group should appear in the same vertical plane, and nodes with the same rank will appear in the same horizontal plane.
library(DiagrammeR)
grViz("
digraph g {
subgraph cluster_0 {
style=filled;
color=lightgrey;
label= To_Accrue
node [shape = rectangle, style = filled, fillcolor = Linen]
bnode [style = invis, shape=point, width = 0, group=g1]
A [group=g1]
B
C [group=g1]
edge [arrowhead='none']
A->bnode
edge [arrowhead='normal']
B->bnode
bnode->C
{rank=same B bnode}
}
subgraph cluster_1 {
style=filled;
color=crimson;
label= Y
node [style=filled,color=blue, shape=folder]
1
2
3
1->2->3
}
}
")
I also edited the original code to generate the following to approach a rotational scenario.
enter image description here
library(DiagrammeR)
grViz("
digraph g {
subgraph cluster_0 {
style=filled;
color=lightgrey;
label= To_Accrue
node [shape = rectangle, style = filled, fillcolor = Linen]
a1 [style = invis, shape=point, width = 0, group=g1]
a2 [style = invis, shape=point, width = 0, group=g2]
a3 [style = invis, shape=point, width = 0, group=g3]
A [group=g1]
B
C [group=g1]
C [group=g2]
D
E [group=g2]
edge [arrowhead='none']
A->a1
C->a2
E->a3
edge [arrowhead='normal']
B->a1 {rank=same B a1}
a1->C
D->a2 {rank=same D a2}
a2->E
F->a3 {rank=same F a3}
a3->G
}
subgraph cluster_1 {
style=filled;
color=crimson;
label= Y
node [style=filled,color=blue, shape=folder]
1
2
3
1->2->3
}
}
")
Related
I'm trying to make an Entity-relationship diagram using the Graphviz DOT language. In my model I have a self-referencing relationship and here I would like the edges to be orthogonal, i.e. consist only of vertical and horizontal lines. Currently I have this diagram:
digraph G {
edge [arrowhead = none]
Entity [shape = box]
Relationship [shape = diamond]
Entity -> Relationship [headport = w, tailport = w]
Relationship -> Entity [headport = e, tailport = e]
}
I tried adding graph [splines = ortho] but then the diagram renders like this:
Any ideas? I'm using version 2.43.0 of DOT.
The ortho implementation is rather flawed, Here is a DIY version. It adds invisible point-shaped nodes to each side of the two ER nodes and then draws edges to connect everything to look "ortho".
digraph G {
splines=false
edge [arrowhead = none]
{ rank=same
Entity [shape = box]
node [shape=point label="" style=invis]
x1 [group=G1]
x2 [group=g2]
x1 -> Entity [tailclip=false]
Entity -> x2 [headclip=false]
}
{ rank=same
Relationship [shape = diamond]
node [shape=point label="" style=invis]
y1 [group=G1]
y2 [group=g2]
y1 -> Relationship [tailclip=false]
Relationship -> y2 [headclip=false]
}
x1 -> y1 [headclip=false tailclip=false]
x2 -> y2 [headclip=false tailclip=false]
}
Giving:
I am trying to plot a regular graph with grViz in R like the below:
using the following code:
grViz("
graph {
# a graph statement
graph [layout = circo]
# a node statement
node [shape = circle,
style = filled,
color = grey,
fillcolor = orange];
nodesep=4
A; B; C; D; E; F; G; H;
# an edge statement
edge [color = grey]
A -- B
B -- C
C -- D
D -- E
E -- F
F -- G
G -- H
H -- A
A -- D
H -- E
B -- G
C -- F
}")
However, I cannot place the nodes in sequential order despite trying the different options for rankdir:
For my flowchart, I have a vertical chart detailing the data flow. However on the downward arrows, I want to add side arrows to describe where the missing data is going. How do I do this? I can't see it in any of the documentation and examples because it tends to be about far more complex things, and I know this is a very basic task!
library(DiagrammeR)
grViz("digraph flowchart {
# node definitions with substituted label text
node [fontname = Helvetica, shape = rectangle, fixedsize = false, width = 1]
1 [label = 'data (100%)']
2 [label = 'data (90.4%)']
3 [label = 'data \\ndata (83.3%)']
4 [label = 'data (66%)']
7 [label = 'data (100%)']
8 [label = 'data (74.4%)']
9 [label = 'data (69.6%)']
10 [label = 'data (55.4%)']
1 -> 2 -> 3 -> 4;
7 -> 8 -> 9 -> 10
} ")
This gives me two side by side panels, but I want arrows coming off the downward arrows where I can put the n for missing data.
The standard trick is to create invisible dummy nodes, then break up each edge into two parts: 1) source -> dummy, and 2) dummy -> target:
library(DiagrammeR)
grViz("digraph flowchart {
# node definitions with substituted label text
node [fontname = Helvetica, shape = rectangle, fixedsize = false, width = 1]
1 [label = 'data (100%)']
2 [label = 'data (74.4%)']
3 [label = 'data (69.6%)']
4 [label = 'data (55.4%)']
m1 [label = 'missing (25.6%)']
m2 [label = 'missing (4.8%)']
node [shape=none, width=0, height=0, label='']
p1 -> 2; p2 -> 3 -> 4;
{rank=same; p1 -> m1}
{rank=same; p2 -> m2}
edge [dir=none]
1 -> p1; 2 -> p2;
}")
I shortened your example for demonstration purposes. In the above, p1 and p2 are invisible dummy nodes. There are three sets of edges:
Downward directed edges from dummy nodes to targets (e.g., p1 -> 2)
Horizontal directed edges from dummy nodes to "missing" nodes. Edge direction is imposed through rank=same.
Undirected edges from source to the dummy nodes
With the following dot code
digraph DG {
G -> V;
G -> E;
G -> P;
G -> C;
}
I generate the following graph
How could I move the node G in the centre? That is I wish to get something like this:
p.s. My experiments with setting the rank of the edge didn't work out.
For the general case, the easiest thing to do is to use twopi or neato instead of dot as your layout engine.
Twopi:
Neato:
If you're truly confined to dot, this will give you close to what you want, though you'll have to customize each graph.
digraph g
{
P -> G [dir=back];
subgraph clusterGVE {
{rank=same V; G; E;}
G -> V [constraint=false];
G -> E;
color=invis;
};
G -> C;
}
I have an undirected graph with the following schema:
graph G {
A -- B;
B -- C;
C -- D;
D -- A;
}
The graph is top to bottom as you see yourself. But I wanted to be in the form of a rectangle where A is top-left and D is bottom-right and I don't really have a clue how to do it.
graph G {
A [
label = A
pos = "0,0!"
]
B [
label = B
pos = "5,0!"
]
C [
label = C
pos = "5,5!"
]
D [
label = D
pos = "0,5!"
]
A -- B;
B -- C;
C -- D;
D -- A;
}
and use neato to generate the image file. (it did not work with dot for me)
I have got another solution without neato I guess that renders with dot properly.
graph G{
{rank=same A B}
{rank=same C D}
A -- B;
B -- C;
D -- A;
D -- C;
}