Given the following DataFrame:
| a | b | c | d |
|---|---|---|---|
| 1 | 0 | 1 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 |
How does one efficiently construct a weighted graph, such that:
- The nodes correspond to the column names;
- Two vertices are connected if they both have 1's in the same line of the DataFrame (e.g. 'a' is connected to 'c' in the first row);
- The weight is equal to the number of times two vertices are connected (e.g. edge 'a'-'c' has weight 2, while 'c'-'d' has weight 1).
Here is how to manually construct this graph using SimpleWeightedGraphs.jl and GraphPlot.jl:
g = SimpleWeightedGraph(4)
add_edge!(g,1,3,2)
add_edge!(g,1,4,2)
add_edge!(g,2,4,1)
add_edge!(g,3,4,1)
nodes = ["a","b","c","d"]
gplot(g,nodelabel=nodes,edgelinewidth=[2,2,1,1])
