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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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.