Message Boards Message Boards

0
|
6315 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How can I highlight edge weight intensities in a weighted graph

I have a weighted graph, which I would like to plot using the AdjacencyGraph command or something similar. I can easily create the picture when the graph is unweighted using the AdjacencyGraph command. Is there an option for this command that will allow me to color the edges in a manner that conveys my graph's varying weight values?

POSTED BY: Paul Fishback
2 Replies

The IGraph/M package makes such styling tasks fairly easy. Suppose you have the following adjacency matrix, containing weights:

wam = {{0, 10, 10, 0, 0, 0, 8, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 5, 18, 0, 
    0}, {5, 0, 0, 20, 0, 0, 0, 20, 0, 0}, {0, 0, 0, 0, 0, 0, 13, 0, 0,
     0}, {0, 0, 8, 0, 0, 11, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0}, {0, 0, 0, 19, 0, 0, 0, 17, 0, 0}, {0, 6, 0, 0, 0, 17, 0, 0, 0,
     0}, {0, 0, 0, 18, 19, 17, 0, 0, 0, 18}, {0, 0, 0, 0, 20, 0, 0, 0,
     0, 0}};

First we make a graph out of it:

g = IGWeightedAdjacencyGraph[wam, EdgeStyle -> Thick];

Then we style:

Legended[
 IGEdgeMap[ColorData["Rainbow"], EdgeStyle -> Rescale@*IGEdgeProp[EdgeWeight], g],
 BarLegend[{"Rainbow", MinMax@IGEdgeProp[EdgeWeight][g]}]
]

enter image description here

POSTED BY: Szabolcs Horvát

Hi Paul,

here I use Opacity to indicate the strength of the link:

windcm = # + Transpose[#] &@ RandomReal[{-0.5, 0.5}, {30, 30}];
CompleteGraph[30, VertexLabels -> "Name", 
 EdgeStyle ->  
  Flatten[Table[(i <-> j) -> 
     RGBColor[Map[1.0 - HeavisideTheta[-# - 0.15] &, windcm][[i, j]], 
      Map[HeavisideTheta[-Abs[#] + 0.15] &, windcm][[i, j]], 
      Map[1.0 - HeavisideTheta[-0.15 + #] &, windcm][[i, j]], 
      Map[0.75*Abs[#] &, windcm][[i, j]]], {i, 1, 30}, {j, 1, i}]]]

enter image description here

You see that I use RGBColor. Red indicates positive interaction, Blue negative interaction and the magnitude is represented by the different opacities. It is easy to adapt that to all sorts of colours, of course. This one would be for grayscale colouring:

CompleteGraph[30, VertexLabels -> "Name", 
EdgeStyle ->  Flatten[Table[(i <-> j) -> GrayLevel[1.5*Abs[windcm[[i, j]]]], {i, 1, 30}, {j, 1, i}]]]

Cheers,

Marco

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract