Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to create a signed graph where the edges of my graph are either green (for a positive correlation) or red (for a negative correlation). I only managed to create a graph from a tresholded adjacency matrix so far (greater than x), but struggling with this and didn't find a function in mathematica. I'm also not sure if it's even possible :/

Is it also possible to make the edge lines thicker for a stronger correlation?

Thanks in advance

share|improve this question

1 Answer 1

up vote 4 down vote accepted
n = 3;
corrMat = RandomReal[{-1, 1}, {n, n}]; 
      Style[DirectedEdge[i, j], If[corrMat[[i, j]] > 0, Green, Red], 
      Thickness[.001 Abs[corrMat[[i, j]]]]], {i, n}, {j, n}]]

Mathematica graphics


Perhaps better:

Graph[Flatten@ MapIndexed[
      Style[DirectedEdge @@ #2, If[#1 > 0, Green, Red], Thickness[.001 Abs[#1]]] &, 
      corrMat, {2}]]
share|improve this answer
Thank you very much, works perfectly :) – holistic Jan 28 '14 at 14:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.