I'm trying to make a SEM graph using R and DiagrammeR. I have the graph set up but I'm trying to have some of the nodes (CSEW, ONS and Police) at the bottom of the graph to make it easier to read.
Here is what I have so far. Any recommendations in how to move the three circles to the bottom would be welcomed.
library(DiagrammeR)
grViz("
digraph MTMM {
subgraph {
node [shape = box, fixedsize = true, width = 1]
rank = same; bike_c; bike_p; bike_o
burg_c; burg_p; burg_o
theft_c; theft_p; theft_o
viol_c; viol_p; viol_o
}
subgraph {
node [shape = circle, fixedsize = true, width = 1]
Bicycle; Burglary; Theft; Violence
}
subgraph {
node [shape = circle, fixedsize = true, width = 1]
CSEW; ONS; Police
}
Bicycle -> {bike_c bike_p bike_o}
Burglary -> {burg_c burg_p burg_o}
Theft -> {theft_c theft_p theft_o}
Violence -> {viol_c viol_p viol_o}
CSEW -> {bike_c burg_c theft_c viol_c} [label = '1']
ONS -> {bike_o burg_o theft_o viol_o} [label = '1']
Police -> {bike_p burg_p theft_p viol_p} [label = '1']
{rank = same; CSEW; ONS; Police}
{rank = same; Bicycle; Burglary; Theft; Violence}
}
")
If you want have node A
above node B
, you must point from A -> B
, this is graphviz' fundamental logic. If you want the arrow point in the other direction, you do so by telling graphviz: A -> B[ dir = back]
.
In your case, replace the three lines concerned with
{bike_c burg_c theft_c viol_c} -> CSEW [dir = back, label = '1']
{bike_o burg_o theft_o viol_o} -> ONS[dir = back, label = '1']
{bike_p burg_p theft_p viol_p} -> Police[dir = back, label = '1']
which gives you