# Invisible graph edges

I have a fairly sparse adjacency matrix for which I can draw the graph. Right now, two nodes $i$ and $j$ are connected, or not ($w_{ij} \in \{0,1\}$). However, I have come up with a way to define new connections between previously unconnected vertices, and assign some value $0\le w_{ij}\le 1$ to these new edges. I want the resulting graph to be drawn with these new edges taken into account as far as the layout is concerned (i.e. the spring-electrical-embedding algorithm should include these edges). I do not, however, want these edges to be drawn visually.

The only solution I can come up with myself is to calculate the node-coordinates first, then cross-reference them with the adjacency-matrix and only draw the vertices in some sort of scatterplot. This seems a little inefficient and overcomplicated though... Any shortcuts?

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Dec 11, 2014 at 16:56

If somehow you don't like @belisarius's answer (it is very neat, there's no reason not to use it!), you can also get the vertex coordinates from the complete graph and force them on the original graph.

Stealing some of his answer's definitions:

g = AdjacencyGraph@Ceiling@newAdjM
PropertyValue[{g, #}, VertexCoordinates] & /@ VertexList[g]
GraphicsRow[{%, g}]


• Your code doesn't work on my V9. Are you using v10? Dec 11, 2014 at 17:16
• Yup! 10.0 for Mac OS X x86 (64-bit) But you're right! There was a Ceiling missing! Dec 11, 2014 at 17:17
• GraphEmbedding[g] might be better to compute coordinates. Dec 11, 2014 at 17:20
• @Aisamu Thanks! I accepted this answer, because it was the first one I could understand at a glance. Man, I hate Mathematica syntax... Dec 11, 2014 at 20:34

You could use HighlightGraph:

m = {{0, 0.5, 1}, {1, 0, 0}, {0.1, 1, 0}};

GraphicsRow[{g,
HighlightGraph[g,
Style[e_ /; (PropertyValue[{g, e}, EdgeWeight] < 1),
Transparent]]}]


• That's a neat one Dec 11, 2014 at 17:18

Another way is use AdjacencyGraph with the full graph and setting the EdgeStyle so that edges smaller than 1 are not visible:

paint[adj_?MatrixQ, style_] := AdjacencyGraph[
EdgeStyle -> (DirectedEdge @@ # -> style & /@ Position[adj, _?(0 < # < 1 &)])]


and then you can go with

adjMat = RandomInteger[{0, 1}, {10, 10}] /.
{0 :> If[RandomChoice[{True, False}], RandomReal[], 0]};
{{v, 1}, 0, 1}
]


• In v9 AdjacencyGraph[] fails with non integer values on the matrix :( Dec 11, 2014 at 17:21
• @belisarius That's why I use Ceiling. Doesn't the above code work for you?? Because I tested it on V9. Dec 11, 2014 at 17:22
• Sorry, my comment was a side-note, not a complain. Bad wording. Dec 11, 2014 at 17:24
SeedRandom[42];

(* set up the before/after adjecency matrix *)
adjM = RandomInteger[{0, 1}, {5, 5}];
twoEdges = Position[adjM, 0][[1 ;; 2]];