0
$\begingroup$

For this example I work with the next dataset:

 data = {{1, 0.013, 0.113, 0.017, 0.005, 0.006, 0.009, 0.015, 0.012, 
        0.001}, {0.91, 1, 0.113, 0.117, 0.015, 0.106, 0.009, 0.015, 0.012,
         0.001}, {0.19, 0.013, 1, 0.017, 0.45, 0.006, 0.69, 0.015, 0.012, 
        0.001}, {0.29, 0.013, 0.113, 1, 0.005, 0.006, 0.009, 0.015, 0.012,
         0.001}, {0.49, 0.013, 0.113, 0.017, 1, 0.006, 0.009, 0.015, 
        0.012, 0.001}, {0.59, 0.013, 0.113, 0.017, 0.005, 1, 0.009, 0.015,
         0.012, 0.001}, {0.39, 0.013, 0.113, 0.017, 0.005, 0.006, 1, 
        0.015, 0.012, 0.001}, {0.999, 0.013, 0.113, 0.47, 0.55, 0.006, 
        0.009, 1, 0.012, 0.001}, {0.29, 0.013, 0.113, 0.017, 0.005, 0.006,
         0.009, 0.015, 1, 0.001}, {0.09, 0.013, 0.113, 0.017, 0.005, 
        0.006, 0.009, 0.015, 0.012, 1}};

head = {"K1", "K2", "K3", "K4", "K5", "K6", "K7", "K8", "K9", "K10"};

I want to create a graph with the thickness of the edges based on the values in the Adjacencymatrix

dfMaxtrix[θ_] :=  
 ReplacePart[data, {i_, i_} -> 0] /. {x_ /; x > θ -> 1,    
   x_ /; x <= θ -> 0}
dfMaxtrixg[θ_] :=  
 ReplacePart[   data, {i_, i_} -> 0] /. {x_ /; x > θ -> x,    
   x_ /; x <= θ -> 0}

If I work with al edges, the next code will work fine:

edgestyle1 = 
  DeleteCases[ArrayRules[SparseArray[dfMaxtrixg[0.0]]], {_, _} -> 0];
edgestyle2 = 
  Table[edgestyle1[[i]] /. {x_, y_} -> (x <-> y), {i, 1, 
    Length[edgestyle1]}];
edgestyle3 = (First@# -> 
      Directive[Thickness[(Last@#)/10], Opacity[.5]]) & /@ edgestyle2;

graph1 = AdjacencyGraph[dfMaxtrix[0.0], 
  VertexLabels -> 
   MapThread[
    Rule, {Range[Length[head]], 
     Style[#, 12, GrayLevel[.1], FontFamily -> "Verdana"] & /@ head}],
   EdgeStyle -> edgestyle3, ImageSize -> 500]

enter image description here

Now I want to create a graph with a subset of vertexs. For example only the vertexs when they have a value larger then 0.2. I adjust de 'dfMaxtrixg' using infinity instead of 0

dfMaxtrixg[θ_] :=  
 ReplacePart[   
   data, {i_, i_} -> ∞] /. {x_ /; x > θ -> x,    
   x_ /; x <= θ -> ∞}

Subgraph[WeightedAdjacencyGraph[dfMaxtrixg[0.2]], 
 KCoreComponents[WeightedAdjacencyGraph[dfMaxtrixg[0.2]], 2], 
 VertexLabels -> "Name"]

enter image description here

How can I change the edgestyle-> Thickness based on the values of dfMaxtrixg[0.2]

$\endgroup$
  • $\begingroup$ Your code doesn't seem to work as posted to reproduce the figure you showed. You don't seem to be handling the Infinity values that you introduce on the diagonal and that ultimately get passed to Thickness. Also what is kop? It is VERY important that you test the code you post in a fresh kernel, to check that it actually works and does what you expect. $\endgroup$ – MarcoB Feb 15 '17 at 0:12
  • $\begingroup$ Hi MarcoB. Thanks for your comment. I changed my script. $\endgroup$ – Michiel van Mens Feb 15 '17 at 7:50
3
$\begingroup$

You could set EdgeStyle after you find a subgraph:

g = WeightedAdjacencyGraph[dfMaxtrixg[0.2]]; 
sg = Subgraph[g, KCoreComponents[g, 2], VertexLabels -> "Name"];
estyle = (# -> 
      With[{w = PropertyValue[{g, #}, EdgeWeight]}, {Arrowheads[w/10],
         Directive[Thickness[w/35], Opacity[.5]]}]) & /@ EdgeList[sg];
Graph[sg, EdgeStyle -> estyle]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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