       Re: Weighted graphs with sum of weights determining vertex placement?

• To: mathgroup at smc.vnet.net
• Subject: [mg112140] Re: Weighted graphs with sum of weights determining vertex placement?
• From: Luci Ellis <luci at verbeia.com>
• Date: Thu, 2 Sep 2010 02:29:45 -0400 (EDT)
• References: <i5idqu\$jtl\$1@smc.vnet.net> <i5l9t5\$7ki\$1@smc.vnet.net>

```Thanks Sjoerd,
This was a really good suggestion. It turns out, though, that some of
the lesser-known options to the function do the trick, namely the
"RepulsiveForcePower" and "StepLength" suboptions to  Method ->
"SpringElectricalEmbedding" .
Using a construction like the below gave good results for q = -0.6 and
r = 1.4. NB you get both arrows, on top of one another, using
DirectedEdges -> True, MultiedgeStyle -> False.

Manipulate[
GraphPlot[rawnums, DirectedEdges -> True, MultiedgeStyle -> False,
VertexRenderingFunction -> ({White, EdgeForm[Black], Disk[#, .04],
Black, Text[names[[#2]], #1]} &),
EdgeRenderingFunction -> (With[{relexp = (rawnums[[#2[], #2[[
2]]]])/100}, {AbsoluteThickness[relexp*20.],
RGBColor[relexp*0.8, relexp*0.8, relexp*0.8],
Arrowheads[0.06 relexp + 0.008], Arrow[#1, 0.05]}] &),
VertexLabeling -> True, ImageSize -> 500,
PlotLabel -> Style["Plot Heading", Bold, 14, FontFamily -> "Arial"],
Method -> {"SpringElectricalEmbedding", "RepulsiveForcePower" -> q,
"StepLength" -> r}], {q, -4, -0.01}, {r, 1., 5.}]

This function might come in handy for some purposes. I used it to
verify that you get the same result for adjacency matrices  as for
lists of rules, and regardless of whether you actually show all the
multiedges.

AdjacencyMatrixToRules[mat_?MatrixQ] /; Equal @@ Dimensions[mat] :=
With[{n = Length[mat]},
Flatten@(Join @@ Table[Table[i -> j, {mat[[i, j]]}], {i, n}, {j, n}])
]

Hope that helps.

Best regards,
Luci

On 2010-09-01 20:28:53 +1000, Sjoerd C. de Vries said:

> With the total weigths in the list sums (sums = Total /@ rawnums)  I
> suppose various constructions like
>
> VertexCoordinateRules -> ((Max[sums] - sums) ({Cos[#], Sin[#]} & /@
>      Table[i, {i, 0, 2 \[Pi] - 2 \[Pi]/8, 2 \[Pi]/8}]))
>
> or
>
> VertexCoordinateRules -> ((8 -
>      Ordering[Ordering[sums]]) ({Cos[#], Sin[#]} & /@
>      Table[i, {i, 0, 2 \[Pi] - 2 \[Pi]/8, 2 \[Pi]/8}]))
>
>
> Cheers -- Sjoerd
>
> On Aug 31, 10:17 am, Luci Ellis <l... at verbeia.com> wrote:
>> Dear all,
>> Suppose I have a weighted adjacency matrix like this:
>>
>> rawnums={{0, 43, 25, 70, 92, 75, 83, 69}, {0, 0, 0, 0, 0, 0, 0, 2}, {6,
>> 28, 0, 1, 0,
>> 3, 0, 3}, {26, 1, 2, 0, 4, 1, 7, 14}, {0, 2, 1, 0, 0, 1, 0, 0}, {7, 1=
> 8, 60,
>> 0, 1, 0, 2, 10}, {49, 2, 2, 6, 3, 7, 0, 1}, {12, 5, 10, 23, 0, 13, 7,=
>  0}}
>>
>> Some vertex labels:
>> names = ToString /@ Range
>>
>> And some code to create a graph with edge thickness based on the
>> weights, like this:
>>
>> GraphPlot[Sign[rawnums], DirectedEdges -> True, MultiedgeStyle -> True,
>> VertexRenderingFunction -> ({White, EdgeForm[Black], Disk[#, .04], Bla=
> ck,
>> Text[names[[#2]], #1]} &),
>> EdgeRenderingFunction -> (With[{relexp = (rawnums[[#2[], #2[]]=
> ])/
>> 100}, {AbsoluteThickness[relexp*20.],
>> RGBColor[relexp*0.8, relexp*0.8, relexp*0.8],
>> Arrowheads[0.06 relexp + 0.008], Arrow[#1, 0.05]}] &),
>> VertexLabeling -> True, ImageSize -> 500,
>>
>> How do I get the vertices with the highest total weights (in this case
>> the sum of each row, since all the columns sum to 100), to sit in the
>> centre of the graph, with the less connected / lower-weighted vertices
>> at the periphery? I have tried all the alternatives in the Method
>> option. VertexCoordinateRules should do the trick, but I have no idea
>> how to specify those rules according to the weights.
>> Any suggestions? I am not a graph theorist so this is new to me.
>>
>> Best regards,
>> Luci

```

• Prev by Date: Re: coordinates in LogLogPlots
• Next by Date: nonlinearfit for data with errors in both coordinates
• Previous by thread: Re: Weighted graphs with sum of weights determining vertex placement?
• Next by thread: fit with cdf of skew normal distriubtion