How can I create a Hasse diagram (or a directed acyclic graph)?

6 views (last 30 days)
I'm trying to create a Hasse diagram with an adjacency matrix
Here is the result I am getting using digraph. It's technically correct, but I would like it to look like this (with or without arrows, the direction is implied by the orientation, although arrows would be useful).
I hope the image is clear! I'm not a very good artist hehe.
If anyone wants to test it out using my data, here is my adjacency matrix (large--500x500 matrix as ASCII) and here is the code I use to pick out the points and plot it using digraph. (Alternatively, the files are attached below--the adjacency matrix is on filebin because I can't upload .dat files here)
Any suggestions? Any help would be appreciated!

Accepted Answer

Conor Kelly
Conor Kelly on 1 Feb 2018
Edited: Conor Kelly on 1 Feb 2018
For anyone else who has this question, I found the answer.
You must create a biograph object. If you already have a causal set and have been able to plot it the way I was using digraph, you simply create a biograph object using
h = biograph(your_link_matrix,label_array);
view(h)
your_link_matrix is the adjacency matrix that represents the causal ordering relation between your events (Note: If your set includes "A precedes B" and "B is preceded by A", you will need to reduce the matrix by removing one of these statements, such that you have only 1's in your matrix. If you are not working on causal sets and have no idea what I'm talking about, disregard this).
label_array is a character array for the events in your causal set. If you are using all of the points in your causal set, then the row number of your matrix is simply the label of your nodes. For instance, if your adjacency matrix looks like this:
causalset = 0 0 1 0
0 0 1 0
-1-1 0 1
0 0-1 0
Then you can simply create the label_array using the following code:
label_array={};
for a=1:length(causalset(1,:))
label_array = horzcat(label_array,num2str(a);
end
(An adjacency matrix must be square anyway, so all rows/columns must have the same length)
One problem I have noticed is that my Hasse diagram is "upside down", but changing the layout of view(biograph) is not as simple as most other matlab figures and there seems to be little documentation on how to do this. A quick fix is to select File > Print to Figure in the Biograph Viewer, then type "axis ij" in the command window.
If anyone else is working on causal sets and encounters this problem and is still having issues, feel free to email me at conorakelly@gmail.com

More Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!