6

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

我的期望(来自 PowerPoint):

预期的

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

实际的

代码:

grViz("
  digraph {

  graph[splines=ortho, nodesep=1]

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

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

2 回答 2

3

你需要使用空白/空节点,像这样,(如果你不希望箭头添加[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

   }
 ")

在此处输入图像描述

于 2018-12-15T17:33:09.750 回答
1

这是适应皮特上述建议的另一种方法 - 使用正交样条的简化代码并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]
     
   }
 ")

输出:

组织结构图输出

于 2020-06-30T16:34:22.103 回答