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]
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"]
How can I change the edgestyle-> Thickness based on the values of dfMaxtrixg[0.2]
Infinity
values that you introduce on the diagonal and that ultimately get passed toThickness
. Also what iskop
? 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