1
votes

I have a dataset with staff and their job roles, and each job role is assigned a code: 0 for top-management, 1 for middle-management, and 2 for general staff. I now want to plot these roles using a hierarchical graph, so that all code 0 staff are on the top, 1 in the middle, and 2 at the bottom. I've found the layout in iGraph to do this (see below), however don't know how to control which nodes appear where. Is there a parameter that I'm missing to control this? Any help would be appreciated.

CSV: https://github.com/Laurie-Bamber/Enron_Corpus/blob/master/15Below_60Employees_1.csv

Role Codes: https://github.com/Laurie-Bamber/Enron_Corpus/blob/master/Dict_role_code.csv

GML: https://github.com/Laurie-Bamber/Enron_Corpus/blob/master/15Below_60Employees_1.gml

P.S. edges refer to emails between staff, not measures of hierarchy.

enter image description here

Code:
G = Graph.Read_GML('Test.gml')
visual_style['layout'] = G.layout_reingold_tilford()
plot(G, **visual_style)
1
can you add the data? or some data at least?seralouk
Sure, I'll upload it to my git.Laurie
Okay. Have you tried root arguments?seralouk
Links above the picture, cheers.Laurie
Not yet, I saw it however thought that the function would only allow for defining one node, not all. Can all be defined using this function?Laurie

1 Answers

3
votes

I am proposing a solution with a slight modification to what you asked for. If you plot the levels vertically and the people at a role level horizontally, there are many people at one level so the labels run into each other. Instead, I am plotting the role levels horizontally and the individuals at a level are spread out vertically, leaving plenty of room to see the labels.

I do not think that there is a pre-built layout function that does what you are asking. However, it is not very hard to make your own layout. The essential part of doing that is to assign x-y coordinates where you want the nodes to be plotted. After that, you can just use the Layout function to convert the coordinates into a layout object.

My scheme for assigning x-y coordinates will be that the x coordinate will be the role level ( 1,2, or 3). I will just assign y-coordinates by making each node at a role level one higher than the previous node at that level. I use a small dictionary to keep track of what height comes next for each of the levels.

I will use the file names of the files that you provided and will assume that these files are in the current working directory.

import csv
from igraph import *

## Load graph
G = Graph.Read_GML('15Below_60Employees_1.gml')

## Load role levels
reader = csv.reader(open('Dict_role_code.csv'))
dx = dict(reader)

## Create a layout
height = { '1':0, '2':0, '3':0 }
COORD = []
for L in G.vs['label']:
    height[dx[L]] = height[dx[L]] + 1
    COORD.append((float(dx[L]), height[dx[L]]))
LO = Layout(COORD)

## Create the style
visual_style = {}
visual_style['vertex_size'] = 8
visual_style['vertex_frame_color'] = 'orange'
visual_style['layout'] = LO
visual_style['margin'] = 60
visual_style['edge_color'] = '#00000044'

plot(G, **visual_style)

Enron

I think that this provides you with a good starting place. You can tweak the placement from here.