Graphviz – horizontal edges between nodes - graph

Good evening, I'm trying to generate graph using graphviz.
I can't figure out how to model horizontal edges between some nodes. I use the next code to generate this graph:
digraph{ rankdir=LR;
//{rank=same; "[0]"; "[10B1]"; "[62]"; "[8]"; "[9]"; "[10]";}
"[0]"->"[37]"; "[37]"->"[4]"; "[37]"->"[8]";
"[8]"->"[9]"; "[9]"->"[10]"; "[62]"->"[8]";
"[0]"->"[10B1]"; "[10B1]"->"[62]"; "[0]"->"[2]";
"[2]"->"[3]"; "[7]"->"[8]"; "[4]"->"[7]";
}
I would like to align the nodes [8], [10B1], [62] [8], [9] and [10] in one horizontal line.

You need to place those nodes in a cluster. Inside that cluster, you can then set rank=lr to have the nodes placed left-to-right. It's important that you define the cluster and the nodes you want in it before you add the connecting edges to the rest of the graph.

An other solution is to have the nodes which have to be aligned share the same value of the group attribute:
digraph{
rankdir=LR;
node[group=main];
"[0]"; "[10B1]"; "[62]"; "[8]"; "[9]";
node[group=""];
"[0]"->"[37]";
"[37]"->"[4]";
"[37]"->"[8]";
"[8]"->"[9]";
"[9]"->"[10]";
"[62]"->"[8]";
"[0]"->"[10B1]";
"[10B1]"->"[62]";
"[0]"->"[2]";
"[2]"->"[3]";
"[7]"->"[8]";
"[4]"->"[7]";
}
You could achieve something similar by adjusting weight or using constraint=false for some edges.
Here's an other example using group, and an other example using weight (same question).

Related

Creating a network graph with set node positions and concentrated edges with both circleheads and arrowheads in R

I've been trying to find a way to replicate the following network graph format in R using DiagrammeR/GraphViz, but without success (ignore the thick black arrow on N1): https://i.stack.imgur.com/oHpQz.png
The graph is a directed graph and each edge in a certain direction either ends with an arrowhead (-->) if the edge value is positive, or a circle/odot (--o) if the edge value is negative. Between a pair of nodes (ex. N1 -- A1), there can be an edge N1 --> A1 and an edge A1 --o N1, and these need to be concentrated so that the two edges look like one line with an arrowhead on one end and a circlehead on the opposite end (like this: o--->). These cannot be parallel or look like two edges ideally.
Another requirement is that the nodes have to be in very specific positions and remain there throughout model simulations where edges might change. From what I have tried and the documentation I have read, this is not possible to do in DOT format, but is possible in neato format.
This is where I get a problem. In neato, I can align the nodes exactly where I want them by defining their x,y positions. However, when I use concentrate = true to create the o---> edge from two otherwise parallel edges, only one type of arrowhead remains. So an edge that's supposed to look like o---> ends up looking like ---> or o---.
This is not a problem in DOT format as concentrate = true does what I want it to do, but in DOT I cannot assign exact node positions. I have tried getting around this using node ranks but without much luck. It seems to stack nodes I want in different ranks within the same rank. As well, concentrate = true doesn't seem to work for edges between nodes within the same rank, as it leaves them as two separate curved edges ---> and o--- without concentrating them.
The reason why I need this to work is because I'm running model simulations where the edges change, and I need to generate hundreds of such graphs. For easy comparison, the nodes need to stay in the same place for consistency.
This is the closest I could come up with using neato format (nodes are positioned the way I want but it's not showing the proper o---> for all the black edges minus self-edges; red edges are true one-way links): https://i.stack.imgur.com/YJBY7.jpg
If only the edges showed up as the proper o---> format, this would be perfect for my needs. If you know of any way to fix this issue using DiagrammeR/GraphViz, or even another program, I would be so grateful. Thanks!
You probably don't need concentrate. Look at arrowtail and dir (https://www.graphviz.org/doc/info/attrs.html#d:arrowtail and https://www.graphviz.org/doc/info/attrs.html#d:dir) and neato -n
digraph c {
graph[label="can neato do the work?"]
node[shape=circle]
a [pos="100,100"]
b [pos="200,100"]
c [pos="300,100"]
a->b [dir=both arrowtail=odot]
c->c [dir=both arrowtail=odot arrowhead=none]
}
Giving:

Highlight subgraph using Wolfram Mathematica

Using Wolfram Mathematica 10.0 I'm trying to highlight a subgraph from the whole graph. As can see at the figure, I succeeded to highlight the subgraph and color the nodes and the edges in a specific color (green).
I want that the subgraph will be on the top, such that it will be convenient to see the subgraph edges and nodes.
Anyone know how to do that?
If you used HighlightGraph, you can reorder the vertices of the graph to define the rendering order. Do it manually, or use IGReorderVertices from the IGraph/M package.
Alternatively, check the "Rendering Order" section of the GraphLayout documentation page—it shows how to define the rendering order without changing the order of the vertex list.
Apparently can do that in an easy way, using "Show":
Show[original graph, subgraph].

Gephi 0.9.1 does not display edge arrows whith curved edges

I have a very simple network consisting of four nodes and seven directed edges.
When I look in the "Preview"-mode at the network with straight edges, the arrows are shown. But if there are edges back and forth between two nodes, only one edge is displayed and information of the edge weight is lost.
Here my example:
If I set the edges to be curved I can see all the edges, but the arrows are gone. See:
Thus, my question: Is there a way to show edge arrows when the edges are curved?
This is a bug or "feature" if you prefer...

Plotting nodes on a graph based on node-pair distances

I was wondering if someone could help with the following problem.
I have a dozen nodes, each a different sized circle between 0 - 10. I have a distance for each node-pair (e.g. node A and B are 6 from each other, etc.)
Given this data, would it be possible to compute the position of each node on a grid?
The distance could be from the centre or the edge of a node.
Thanks.
If you just want to have a graph to look at, try building a neato file where you specify edge distance. Neato is a layout program that is part of the GraphViz package.
This is quite easy. Your example above would look like this:
graph G {
A -- B [len=6]
}

Hidden edges in Graphviz

I'm trying to create a graph using Graphviz (complied with neato), and I would like to place nodes in specific locations. For this, I'm specifying exact edge lengths for all edges. However, I don't want all edges to be visible in the final image.
Do you know of any way to hide edges? I should mention that I tried coloring the edges white, but what happens is that I get white lines painted over the graph nodes - it's not very aesthetic...
It can be done using
nodeA -> nodeB [style=invis]
I found out that another way to go is to define:
outputorder="edgesfirst"
for the graph.

Resources