2

我正在尝试使用 R 和 DiagrammeR 制作 SEM 图。我已经设置了图表,但我试图在图表底部添加一些节点(CSEW、ONS 和 Police),以便于阅读。

这是我到目前为止所拥有的。任何关于如何将三个圆圈移到底部的建议都将受到欢迎。


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}

}


      ") 
4

1 回答 1

1

如果你想在 nodeA上面有 node B,你必须指向 from A -> B,这是 graphviz 的基本逻辑。如果您希望箭头指向另一个方向,您可以通过告诉 graphviz: 来实现A -> B[ dir = back]

在您的情况下,将有关的三行替换为

  {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']

这给了你

在此处输入图像描述

于 2019-06-25T09:43:07.543 回答