英文:
Organisational Chart with independent nodes
问题
我想在HTML小部件中可视化我的公司的组织结构图,以替代当前使用的手绘PDF。
原则上,使用highchart或googleVis包似乎是可行的。不幸的是,当前的组织图中有一些独立的节点,它们位于顶层旁边,可以在我的示例图片中看到“右侧/左侧的其他单位”。
此外,还有更多的独立节点位于左侧,可以在第一个示例图片中看到“其他独立部门”。这些节点可以垂直对齐到其他节点之一,并向下流动。或者,它们可以成为另一个与顶部没有连接的部门,就像我的第二个示例图片中一样。
有没有好的方法来做到这一点?
示例图片是手动添加节点的示例图片。
来自其他问题的MWE:
library(highcharter)
library(dplyr)
highchart() %>%
hc_chart(type = 'organization', inverted = TRUE) %>%
hc_title(text = 'Highcharts Org Chart') %>%
hc_add_series(
name = 'Highsoft',
data = list(
list(from = 'Shareholders', to = 'Board'),
list(from = 'Board', to = 'CEO'),
list(from = 'CEO', to = 'CTO'),
list(from = 'CEO', to = 'CPO'),
list(from = 'CEO', to = 'CSO'),
list(from = 'CEO', to = 'CMO'),
list(from = 'CEO', to = 'HR'),
list(from = 'CTO', to = 'Product'),
list(from = 'CTO', to = 'Web'),
list(from = 'CSO', to = 'Sales'),
list(from = 'CMO', to = 'Market')
),
levels = list(
list(level = 0, color = 'silver', dataLabels = list(color = 'black'), height = 55),
list(level = 1, color = 'silver', dataLabels = list(color = 'black'), height = 55),
list(level = 2, color = '#980104'),
list(level = 4, color = '#359154')
),
nodes = list(
list(id = 'Shareholders'),
list(id = 'Board'),
list(id = 'CEO', title = 'CEO', name = 'Grethe Hjetland', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132317/Grethe.jpg'),
list(id = 'HR', title = 'HR/CFO', name = 'Anne Jorunn Fjarestad', color = '#007ad0', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132314/AnneJorunn.jpg', column = 3, offset = '75%'),
list(id = 'CTO', title = 'CTO', name = 'Christer Vasseng', color = '#007ad0', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12140620/Christer.jpg', column = 4, layout = 'hanging'),
list(id = 'CPO', title = 'CPO', name = 'Torstein Honsi', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12131849/Torstein1.jpg', column = 4),
list(id = 'CSO', title = 'CSO', name = 'Anita Nesse', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132313/Anita.jpg', column = 4, layout = 'hanging'),
list(id = 'CMO', title = 'CMO', name = 'Vidar Brekke', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/13105551/Vidar.jpg', column = 4, layout = 'hanging'),
list(id = 'Product', name = 'Product developers'),
list(id = 'Web', name = 'Web devs, sys admin'),
list(id = 'Sales', name = 'Sales team'),
list(id = 'Market', name = 'Marketing team')
),
colorByPoint = TRUE,
color = '#007ad0',
dataLabels = list(color = 'white'),
borderColor = 'white',
nodeWidth = 65
) %>%
hc_tooltip(outside = TRUE)
<details>
<summary>英文:</summary>
I would like to visualize my company´s organizational chart in an HTML Widget to replace the currently used drawn PDF.
In principle this seems feasible using the highchart or googleVis package. Unfortunately, the current org chart has some independent nodes that are placed next to the top level, see „Other Unit on the right/left“ in my example pictures.
Furthermore, there are even more independent nodes on the left hand side, see „other independent units“ in the first example picture. Those could be vertically aligned to one of the other nodes and just flow down. Alternatively, they could be another department with no connection to the top as in my second example picture.
Is there a good way to do this?
MWE for the picture was taken from this questions:
https://stackoverflow.com/questions/60509365/how-can-we-plot-highcarts-organization-chart-in-r-language
Example Picture with manually added nodes
[![enter image description here][1]][1]
Example picture with additional independent department
[![enter image description here][2]][2]
MWE from other question:
library(highcharter)
library(dplyr)
highchart() %>%
hc_chart(type = 'organization', inverted = TRUE) %>%
hc_title(text = 'Highcharts Org Chart') %>%
hc_add_series(
name = 'Highsoft',
data = list(
list(from = 'Shareholders', to = 'Board'),
list(from = 'Board', to = 'CEO'),
list(from = 'CEO', to = 'CTO'),
list(from = 'CEO', to = 'CPO'),
list(from = 'CEO', to = 'CSO'),
list(from = 'CEO', to = 'CMO'),
list(from = 'CEO', to = 'HR'),
list(from = 'CTO', to = 'Product'),
list(from = 'CTO', to = 'Web'),
list(from = 'CSO', to = 'Sales'),
list(from = 'CMO', to = 'Market')
),
levels = list(
list(level = 0, color = 'silver', dataLabels = list(color = 'black'), height = 55),
list(level = 1, color = 'silver', dataLabels = list(color = 'black'), height = 55),
list(level = 2, color = '#980104'),
list(level = 4, color = '#359154')
),
nodes = list(
list(id = 'Shareholders'),
list(id = 'Board'),
list(id = 'CEO', title = 'CEO', name = 'Grethe Hjetland', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132317/Grethe.jpg'),
list(id = 'HR', title = 'HR/CFO', name = 'Anne Jorunn Fjarestad', color = '#007ad0', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132314/AnneJorunn.jpg', column = 3, offset = '75%'),
list(id = 'CTO', title = 'CTO', name = 'Christer Vasseng', color = '#007ad0', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12140620/Christer.jpg', column = 4, layout = 'hanging'),
list(id = 'CPO', title = 'CPO', name = 'Torstein Honsi', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12131849/Torstein1.jpg', column = 4),
list(id = 'CSO', title = 'CSO', name = 'Anita Nesse', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132313/Anita.jpg', column = 4, layout = 'hanging'),
list(id = 'CMO', title = 'CMO', name = 'Vidar Brekke', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/13105551/Vidar.jpg', column = 4, layout = 'hanging'),
list(id = 'Product', name = 'Product developers'),
list(id = 'Web', name = 'Web devs, sys admin'),
list(id = 'Sales', name = 'Sales team'),
list(id = 'Market', name = 'Marketing team')
),
colorByPoint = TRUE,
color = '#007ad0',
dataLabels = list(color = 'white'),
borderColor = 'white',
nodeWidth = 65
) %>%
hc_tooltip(outside = TRUE)
[1]: https://i.stack.imgur.com/SejTu.png
[2]: https://i.stack.imgur.com/cJGMv.png
</details>
# 答案1
**得分**: 2
以下是代码部分的翻译:
## Simple illustration
最简单的说明方法是通过从示例中简单地删除`list(from = 'CEO', to = 'CTO')`行来实现。
这会中断CEO和CTO之间的链接,但节点仍然保持在其位置,因为它们的位置在`column`参数中指定(因为图表是倒置的)。
## Application to your objective
所以对于左侧/右侧的其他单位:
- 在`data`中:创建链接OU1 -> OU1和OU2 -> OU2
- 在`nodes`中:两个节点,指定`column = 0`
对于独立单位:
- 在`data`中:链接UIs -> UI1和UIs -> UI2
- 在`nodes`中:三个节点,对于顶部节点,指定`column = 4`和`layout = 'hanging'`。
<details>
<summary>英文:</summary>
## Simple illustration
The simplest way to illustrate how this can be done is by simply removing the line `list(from = 'CEO', to = 'CTO')` from your example.
library(highcharter)
library(dplyr)
highchart() %>%
hc_chart(type = 'organization', inverted = TRUE) %>%
hc_title(text = 'Highcharts Org Chart') %>%
hc_add_series(
name = 'Highsoft',
data = list(
list(from = 'Shareholders', to = 'Board'),
list(from = 'Board', to = 'CEO'),
#list(from = 'CEO', to = 'CTO'),
list(from = 'CEO', to = 'CPO'),
list(from = 'CEO', to = 'CSO'),
list(from = 'CEO', to = 'CMO'),
list(from = 'CEO', to = 'HR'),
list(from = 'CTO', to = 'Product'),
list(from = 'CTO', to = 'Web'),
list(from = 'CSO', to = 'Sales'),
list(from = 'CMO', to = 'Market')
),
levels = list(
list(level = 0, color = 'silver', dataLabels = list(color = 'black'), height = 55),
list(level = 1, color = 'silver', dataLabels = list(color = 'black'), height = 55),
list(level = 2, color = '#980104'),
list(level = 4, color = '#359154')
),
nodes = list(
list(id = 'Shareholders'),
list(id = 'Board'),
list(id = 'CEO', title = 'CEO', name = 'Grethe Hjetland', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132317/Grethe.jpg'),
list(id = 'HR', title = 'HR/CFO', name = 'Anne Jorunn Fjarestad', color = '#007ad0', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132314/AnneJorunn.jpg', column = 3, offset = '75%'),
list(id = 'CTO', title = 'CTO', name = 'Christer Vasseng', color = '#007ad0', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12140620/Christer.jpg', column = 4, layout = 'hanging'),
list(id = 'CPO', title = 'CPO', name = 'Torstein Honsi', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12131849/Torstein1.jpg', column = 4),
list(id = 'CSO', title = 'CSO', name = 'Anita Nesse', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132313/Anita.jpg', column = 4, layout = 'hanging'),
list(id = 'CMO', title = 'CMO', name = 'Vidar Brekke', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/13105551/Vidar.jpg', column = 4, layout = 'hanging'),
list(id = 'Product', name = 'Product developers'),
list(id = 'Web', name = 'Web devs, sys admin'),
list(id = 'Sales', name = 'Sales team'),
list(id = 'Market', name = 'Marketing team')
),
colorByPoint = TRUE,
color = '#007ad0',
dataLabels = list(color = 'white'),
borderColor = 'white',
nodeWidth = 65
) %>%
hc_tooltip(outside = TRUE)
[![enter image description here][1]][1]
This breaks the link between CEO and CTO but nodes remain in position because their position is specified in the `column` argument (which in the end rather corresponds to rows as the chart is inverted).
## Application to your objective
So for the left/right other units:
- In `data`: Create links OU1 -> OU1 and OU2 -> OU2
- In `nodes`: The two nodes, specifying `column = 0`
And for the independent units:
- In `data`: The links UIs -> UI1 and UIs -> UI2
- In `nodes`: The three nodes, specifying for the top one `column = 4` and `layout = 'hanging'`
library(highcharter)
library(dplyr)
highchart() %>%
hc_chart(type = 'organization', inverted = TRUE) %>%
hc_title(text = 'Highcharts Org Chart') %>%
hc_add_series(
name = 'Highsoft',
data = list(
# Added ###########
list(from = 'OU1', to = 'OU1'),
list(from = 'OU2', to = 'OU2'),
###################
list(from = 'Shareholders', to = 'Board'),
list(from = 'Board', to = 'CEO'),
list(from = 'CEO', to = 'CTO'),
list(from = 'CEO', to = 'CPO'),
list(from = 'CEO', to = 'CSO'),
list(from = 'CEO', to = 'CMO'),
list(from = 'CEO', to = 'HR'),
# Added #######################
list(from = 'IUs', to = 'IU1'),
list(from = 'IUs', to = 'IU2'),
###############################
list(from = 'CTO', to = 'Product'),
list(from = 'CTO', to = 'Web'),
list(from = 'CSO', to = 'Sales'),
list(from = 'CMO', to = 'Market')
),
levels = list(
list(level = 0, color = 'silver', dataLabels = list(color = 'black'), height = 55),
list(level = 1, color = 'silver', dataLabels = list(color = 'black'), height = 55),
list(level = 2, color = '#980104'),
list(level = 4, color = '#359154')
),
nodes = list(
# Added #####
list(id = 'OU1', name = "Other Unit 1", column = 0),
list(id = 'OU2', name = "Other Unit 2", column = 0),
##############
list(id = 'Shareholders'),
list(id = 'Board'),
list(id = 'CEO', title = 'CEO', name = 'Grethe Hjetland', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132317/Grethe.jpg'),
list(id = 'HR', title = 'HR/CFO', name = 'Anne Jorunn Fjarestad', color = '#007ad0', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132314/AnneJorunn.jpg', column = 3, offset = '75%'),
# Added #####
list(id = 'IUs', name = 'Independent units', column = 4, layout = 'hanging'),
list(id = 'IU1', name = 'Independent units #1'),
list(id = 'IU2', name = 'Independent units #2'),
#############################################
list(id = 'CTO', title = 'CTO', name = 'Christer Vasseng', color = '#007ad0', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12140620/Christer.jpg', column = 4, layout = 'hanging'),
list(id = 'CPO', title = 'CPO', name = 'Torstein Honsi', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12131849/Torstein1.jpg', column = 4),
list(id = 'CSO', title = 'CSO', name = 'Anita Nesse', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/12132313/Anita.jpg', column = 4, layout = 'hanging'),
list(id = 'CMO', title = 'CMO', name = 'Vidar Brekke', image = 'https://wp-assets.highcharts.com/www-highcharts-com/blog/wp-content/uploads/2018/11/13105551/Vidar.jpg', column = 4, layout = 'hanging'),
list(id = 'Product', name = 'Product developers'),
list(id = 'Web', name = 'Web devs, sys admin'),
list(id = 'Sales', name = 'Sales team'),
list(id = 'Market', name = 'Marketing team')
),
colorByPoint = TRUE,
color = '#007ad0',
dataLabels = list(color = 'white'),
borderColor = 'white',
nodeWidth = 65
) %>%
hc_tooltip(outside = TRUE)
[![enter image description here][2]][2]
[1]: https://i.stack.imgur.com/WTFJW.png
[2]: https://i.stack.imgur.com/ZRbY3.png
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论