2

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}

}


      ") 

1 Answer 1

1

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

enter image description here

1
  • Great answer. Thank you!
    – Alex
    Sep 21, 2019 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.