【问题标题】:Creating an organizational chart in R在 R 中创建组织结构图
【发布时间】:2018-12-13 01:05:36
【问题描述】:

我需要在 R 中绘制公司的组织结构图。我有一个示例,但我希望箭头离开同一点。

我的期望(来自 PowerPoint):

我得到了什么(在 R 中):

代码:

grViz("
  digraph {

  graph[splines=ortho, nodesep=1]

  node[shape=box]
  President;Fun1;Fun2;Fun3;

  President->{Fun1,Fun2,Fun3}
  }
  ")

【问题讨论】:

    标签: r diagrammer organizational-chart


    【解决方案1】:

    您需要使用空白/空节点,类似这样,(如果您不希望箭头将 [dir = none] 添加到最后一行,例如 (blank_3 -> Fun1 [dir = none]):

    library(DiagrammeR)
    
    grViz("
      digraph {
    
      node[shape=box, width = 4, height = 1]
    
      blank_1 [label = '',color = white];
      President;
      blank_2 [label = '',color = white];
    
      blank_3[label = '', width = 0.01, height = 0.01];
      blank_4[label = '', width = 0.01, height = 0.01];
      blank_5[label = '', width = 0.01, height = 0.01];
    
      Fun1;
      Fun2;
      Fun3;
    
      {rank = same; blank_1 President blank_2}
      {rank = same; blank_3 blank_4 blank_5}
      {rank = same; Fun1 Fun2 Fun3}
    
      blank_1 -> President [dir = none, color = White]
      President -> blank_2 [dir = none, color = White]
      President -> blank_4 [dir = none]
      blank_1 -> blank_3 [dir = none, color = White]
      blank_2 -> blank_5 [dir = none, color = White]
      blank_3 -> blank_4 [dir = none]
      blank_4 -> blank_5 [dir = none]
      blank_3 -> Fun1
      blank_4 -> Fun2
      blank_5 -> Fun3
    
       }
     ")
    

    【讨论】:

      【解决方案2】:

      这里有另一种方法来适应皮特的上述建议 - 使用正交样条和arrowhead = none 替代dir = none 的简化代码:

      grViz("
        digraph {
      
      splines=ortho
      
      #President node
        node[shape=box,
        fixedsize = true,
        width = 2,
        height = 1]
      'President';
      
      #Fun nodes
      node[shape=square,
              fixedsize = true,
              width = 1.0]
      'Fun1'; 'Fun2'; 'Fun3'
      
      #Blank node
        blank_1[label='', width = 0, height = 0];
      
      
      #President through blank pathway
       'President' -> blank_1[arrowhead = none]
       blank_1 -> 'Fun1'[arrowhead = none]
       blank_1 -> 'Fun2'[arrowhead = none]
       blank_1 -> 'Fun3'[arrowhead = none]
           
         }
       ")
      

      输出:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-04-09
        • 1970-01-01
        • 2017-12-11
        • 1970-01-01
        • 2016-12-24
        • 2016-06-15
        相关资源
        最近更新 更多