A few weeks ago I posted an article describing how to display simple Network Diagrams with Curved Links using SGPLOT procedure. The key requirement is that the node positions have to be computed by user. Often, for simple diagrams, nodes can be positioned using a simple layered layout. Separately, I also posted some articles on creating InfoGraphs using SAS.
In this article, I am combining these ideas to display a diagram with directed curved links. In the graph on the right, I have replaced the nodes with icons for the persons involved in the social network. These icons could represent people or types of services, like "Providers" and "Patients".
As described in the previous article, the node and link data needs to be provided.
Node data includes "NodeId", "Group" for type of node, the "Image Icon" that will represent the group, and the NodeX and NodeY.
The link data includes"LinkId", "From" and "To" nodeids. Optionally, we could include some measure of the link response. In this example, I have skipped link response. Arrowheads are added to display the direction of the link flow.
SAS 9.4 program:
proc sgplot data=network2(where=(linkid ne 10)) noautolegend aspect=1;
symbolimage name=Group1 image="&file1";
symbolimage name=Group2 image="&file2";
styleattrs datasymbols=(group1 group2 group3 group4 group5
group6 group7 group8 group9) backcolor=cxfaf3f0;
spline x=xls y=yls / group=LinkId lineattrs=graphdatadefault arrowheadpos=end
arrowheadshape=filled arrowheadscale=0.5;
scatter x=xn y=yn / group=group markerattrs=(size=40)
dataskin=sheen datalabel=name datalabelpos=bottom;
xaxis min=0 max=4 display=none offsetmin=0.1 offsetmax=0.1;
yaxis min=0 max=4 display=none offsetmin=0.15 offsetmax=0.15;
run;
In the above program, I have trimmed some of the SymbolImage statements to conserve space. We need nine such statements to cover all the icons as shown in the code linked below.
Double Links. The diagram above only has single links. So, having curved links is mainly an aesthetic feature. The curved links are computed as a 3 node curve displayed using the SPLINE statement with arrowheads. The middle node is computed using vector math as shown in the full code linked below.
However, curved links are essential for diagrams with double links. In the diagram on the right, "Ted" and "Bill" have links in both direction. In such cases, we need to curve the links so we can see each of the link and the arrowhead clearly. The nice thing is the algorithm for computing the offset aubomatically goes in the other direction if the "From" and "To" nodes are reversed.
The code uses a factor "Off" to determine the "Bend" of the curve. Off=15 means the bend is 15% of the length. The graph on the right uses a "Bend" of 25% as indicated in the title.
The code also uses "FS" as the factor making the link end stop short of the mode. Value of FS is the % of the distance to be shortened in the direction of the vector to the midpoint. This is important as if we shorten to the original point, it does not look right for curved links.
Shortening the links is important as we do not want to hide the arrowhead when we draw the icons or nodes on top.
Just for comparison, the diagram below has a "Bend" of 40%.
Full SAS 9.4 code: Directed_Links_Icons
Icon Zip file: Node_Icons
To run the code, you will need to put the icons in a folder on your computer, and then put the folder name in place of <Icons folder> in the code.