简体   繁体   English

在 R 中创建组织结构图

[英]Creating an organizational chart in R

I need to draw an organizational chart of the company in R. I have an example but I would like the arrows to leave the same point.我需要在 R 中绘制公司的组织结构图。我有一个例子,但我希望箭头留在同一点。

What I expect (from PowerPoint):我的期望(来自 PowerPoint):

预期的

What I got (in R):我得到了什么(在 R 中):

实际的

Code:代码:

grViz("
  digraph {

  graph[splines=ortho, nodesep=1]

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

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

you need to utilise blank/empty nodes, something like this, (if you don't want the arrows add [dir = none] to the last lines eg ( blank_3 -> Fun1 [dir = none] ):你需要利用空白/空节点,像这样,(如果你不希望箭头添加[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

   }
 ")

在此处输入图像描述

Here's another way to adapt Pete's suggestion above - a simplified code that uses ortho splines and arrowhead = none as an alternative to dir = none :这是采用上述 Pete 建议的另一种方法 - 使用正交样条和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]
     
   }
 ")

Output:输出:

组织结构图输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM